Skip to content

Commit 5d1691d

Browse files
committed
improve onEnter typing
1 parent 1d447ad commit 5d1691d

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

react-router.d.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -531,19 +531,36 @@ declare module ReactRouter {
531531
* Called when a route is about to be entered. It provides the next router state and a function to redirect to another path. this will be the route instance that triggered the hook.
532532
*
533533
* If callback is listed as a 3rd argument, this hook will run asynchronously, and the transition will block until callback is called.
534-
*
535-
* @param {*} nextState
536-
* @param {(location: LocationDescriptor) => void} replace
537-
* @param {() => void} [callback]
538534
*/
539-
onEnter?(nextState: any, replace: (location: LocationDescriptor) => void, callback?: () => void): void;
535+
onEnter?: EnterHook;
540536

541537
/**
542538
* Called when a route is about to be exited.
543539
*/
544540
onLeave?(): void;
545541
}
546542

543+
type Component = ReactComponent<any> | string;
544+
545+
type RouterState = {
546+
location: Location;
547+
routes: Array<Route>;
548+
params: Params;
549+
components: Array<Component>;
550+
};
551+
552+
type EnterHook = (nextState: RouterState, replace: RedirectFunction, callback?: Function) => any;
553+
554+
type RedirectFunction = (state: LocationState, pathname: Pathname | Path, query?: Query) => void;
555+
556+
type LocationState = Object;
557+
558+
type Path = string;
559+
560+
type Pathname = string;
561+
562+
type Query = Object;
563+
547564
/**
548565
* An <IndexRoute> allows you to provide a default "child" to a parent route when visitor is at the URL of the parent.
549566
*

0 commit comments

Comments
 (0)