UNPKG

3.27 kBTypeScriptView Raw
1// Type definitions for React Router 5.1
2// Project: https://github.com/ReactTraining/react-router
3// Definitions by: Huy Nguyen <https://github.com/huy-nguyen>
4// Philip Jackson <https://github.com/p-jackson>
5// John Reilly <https://github.com/johnnyreilly>
6// Sebastian Silbermann <https://github.com/eps1lon>
7// Daniel Nixon <https://github.com/danielnixon>
8// Tony Ward <https://github.com/ynotdraw>
9// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
10// TypeScript Version: 3.1
11
12import { match } from 'react-router';
13import * as React from 'react';
14import * as H from 'history';
15
16export {
17 generatePath,
18 PromptProps,
19 Prompt,
20 MemoryRouterProps,
21 MemoryRouter,
22 RedirectProps,
23 Redirect,
24 RouteChildrenProps,
25 RouteComponentProps,
26 RouteProps,
27 Route,
28 RouterProps,
29 Router,
30 StaticRouterProps,
31 StaticRouter,
32 SwitchProps,
33 Switch,
34 match,
35 matchPath,
36 withRouter,
37 RouterChildContext,
38 useHistory,
39 useLocation,
40 useParams,
41 useRouteMatch,
42} from 'react-router';
43
44export interface BrowserRouterProps {
45 basename?: string | undefined;
46 getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
47 forceRefresh?: boolean | undefined;
48 keyLength?: number | undefined;
49}
50export class BrowserRouter extends React.Component<BrowserRouterProps, any> {}
51
52export interface HashRouterProps {
53 basename?: string | undefined;
54 getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
55 hashType?: 'slash' | 'noslash' | 'hashbang' | undefined;
56}
57export class HashRouter extends React.Component<HashRouterProps, any> {}
58
59export interface LinkProps<S = H.LocationState> extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
60 component?: React.ComponentType<any> | undefined;
61 to: H.LocationDescriptor<S> | ((location: H.Location<S>) => H.LocationDescriptor<S>);
62 replace?: boolean | undefined;
63 innerRef?: React.Ref<HTMLAnchorElement> | undefined;
64}
65export function Link<S = H.LocationState>(
66 ...params: Parameters<Link<S>>
67): ReturnType<Link<S>>;
68
69export interface Link<S = H.LocationState>
70 extends React.ForwardRefExoticComponent<
71 React.PropsWithoutRef<LinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
72 > {}
73
74export interface NavLinkProps<S = H.LocationState> extends LinkProps<S> {
75 activeClassName?: string | undefined;
76 activeStyle?: React.CSSProperties | undefined;
77 exact?: boolean | undefined;
78 strict?: boolean | undefined;
79 isActive?<Params extends { [K in keyof Params]?: string }>(match: match<Params> | null, location: H.Location<S>): boolean;
80 location?: H.Location<S> | undefined;
81}
82export function NavLink<S = H.LocationState>(
83 // TODO: Define this as ...params: Parameters<NavLink<S>> when only TypeScript >= 3.1 support is needed.
84 props: React.PropsWithoutRef<NavLinkProps<S>> & React.RefAttributes<HTMLAnchorElement>,
85): ReturnType<NavLink<S>>;
86export interface NavLink<S = H.LocationState>
87 extends React.ForwardRefExoticComponent<
88 React.PropsWithoutRef<NavLinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
89 > {}
90
\No newline at end of file