UNPKG

3.66 kBTypeScriptView Raw
1// Type definitions for react-router-dom 5.3
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// Pirasis Leelatanon <https://github.com/1pete>
10// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
11// TypeScript Version: 3.1
12
13import { match } from 'react-router';
14import * as React from 'react';
15import * as H from 'history';
16
17export {
18 generatePath,
19 PromptProps,
20 Prompt,
21 MemoryRouterProps,
22 MemoryRouter,
23 RedirectProps,
24 Redirect,
25 RouteChildrenProps,
26 RouteComponentProps,
27 RouteProps,
28 Route,
29 RouterProps,
30 Router,
31 StaticRouterProps,
32 StaticRouter,
33 SwitchProps,
34 Switch,
35 match,
36 matchPath,
37 withRouter,
38 RouterChildContext,
39 useHistory,
40 useLocation,
41 useParams,
42 useRouteMatch,
43} from 'react-router';
44
45export interface BrowserRouterProps {
46 basename?: string | undefined;
47 children?: React.ReactNode;
48 getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
49 forceRefresh?: boolean | undefined;
50 keyLength?: number | undefined;
51}
52export class BrowserRouter extends React.Component<BrowserRouterProps, any> {}
53
54export interface HashRouterProps {
55 basename?: string | undefined;
56 children?: React.ReactNode;
57 getUserConfirmation?: ((message: string, callback: (ok: boolean) => void) => void) | undefined;
58 hashType?: 'slash' | 'noslash' | 'hashbang' | undefined;
59}
60export class HashRouter extends React.Component<HashRouterProps, any> {}
61
62export interface LinkProps<S = H.LocationState> extends React.AnchorHTMLAttributes<HTMLAnchorElement> {
63 component?: React.ComponentType<any> | undefined;
64 to: H.LocationDescriptor<S> | ((location: H.Location<S>) => H.LocationDescriptor<S>);
65 replace?: boolean | undefined;
66 innerRef?: React.Ref<HTMLAnchorElement> | undefined;
67}
68export function Link<S = H.LocationState>(
69 ...params: Parameters<Link<S>>
70): ReturnType<Link<S>>;
71
72export interface Link<S = H.LocationState>
73 extends React.ForwardRefExoticComponent<
74 React.PropsWithoutRef<LinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
75 > {}
76
77export interface NavLinkProps<S = H.LocationState> extends Omit<LinkProps<S>, "className" | "style"> {
78 activeClassName?: string | undefined;
79 activeStyle?: React.CSSProperties | undefined;
80 exact?: boolean | undefined;
81 strict?: boolean | undefined;
82 isActive?<Params extends { [K in keyof Params]?: string }>(match: match<Params> | null, location: H.Location<S>): boolean;
83 location?: H.Location<S> | undefined;
84 className?: string | ((isActive: boolean) => string) | undefined;
85 style?:
86 | React.CSSProperties
87 | ((isActive: boolean) => React.CSSProperties)
88 | undefined;
89 sensitive?: boolean | undefined;
90}
91export function NavLink<S = H.LocationState>(
92 // TODO: Define this as ...params: Parameters<NavLink<S>> when only TypeScript >= 3.1 support is needed.
93 props: React.PropsWithoutRef<NavLinkProps<S>> & React.RefAttributes<HTMLAnchorElement>,
94): ReturnType<NavLink<S>>;
95export interface NavLink<S = H.LocationState>
96 extends React.ForwardRefExoticComponent<
97 React.PropsWithoutRef<NavLinkProps<S>> & React.RefAttributes<HTMLAnchorElement>
98 > {}
99
\No newline at end of file