1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | import * as React from 'react';
|
12 |
|
13 | export interface HLocation<S = unknown> {
|
14 | pathname: string;
|
15 | search: string;
|
16 | state: S;
|
17 | hash: string;
|
18 | key?: string | undefined;
|
19 | }
|
20 | export type WindowLocation<S = unknown> = Window['location'] & HLocation<S>;
|
21 |
|
22 | export type HistoryActionType = 'PUSH' | 'POP';
|
23 | export type HistoryLocation = WindowLocation & { state?: any };
|
24 | export interface HistoryListenerParameter {
|
25 | location: HistoryLocation;
|
26 | action: HistoryActionType;
|
27 | }
|
28 | export type HistoryListener = (parameter: HistoryListenerParameter) => void;
|
29 | export type HistoryUnsubscribe = () => void;
|
30 |
|
31 | export interface History {
|
32 | readonly location: HistoryLocation;
|
33 | readonly transitioning: boolean;
|
34 | listen: (listener: HistoryListener) => HistoryUnsubscribe;
|
35 | navigate: NavigateFn;
|
36 | }
|
37 |
|
38 | export class Router extends React.Component<RouterProps & React.HTMLProps<HTMLDivElement>> {}
|
39 |
|
40 | export interface RouterProps {
|
41 | basepath?: string | undefined;
|
42 | primary?: boolean | undefined;
|
43 | location?: WindowLocation | undefined;
|
44 | component?: React.ComponentType | string | undefined;
|
45 | }
|
46 |
|
47 | export type RouteComponentProps<TParams = {}> = Partial<TParams> & {
|
48 | path?: string | undefined;
|
49 | default?: boolean | undefined;
|
50 | location?: WindowLocation | undefined;
|
51 | navigate?: NavigateFn | undefined;
|
52 | uri?: string | undefined;
|
53 | };
|
54 |
|
55 | export type Omit<T, K> = Pick<T, Exclude<keyof T, K>>;
|
56 |
|
57 | export type AnchorProps = Omit<
|
58 | React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>,
|
59 | 'href'
|
60 | >;
|
61 |
|
62 | export interface LinkProps<TState> extends AnchorProps {
|
63 | to: string;
|
64 | replace?: boolean | undefined;
|
65 | getProps?: ((props: LinkGetProps) => {}) | undefined;
|
66 | state?: TState | undefined;
|
67 | /** @deprecated If using React >= 16.4, use ref instead. */
|
68 | innerRef?: React.Ref<HTMLAnchorElement> | undefined;
|
69 | }
|
70 |
|
71 | export interface LinkGetProps {
|
72 | isCurrent: boolean;
|
73 | isPartiallyCurrent: boolean;
|
74 | href: string;
|
75 | location: WindowLocation;
|
76 | }
|
77 |
|
78 | export function Link<TState>(
|
79 |
|
80 | props: React.PropsWithoutRef<LinkProps<TState>> & React.RefAttributes<HTMLAnchorElement>,
|
81 | ): ReturnType<Link<TState>>;
|
82 | export interface Link<TState>
|
83 | extends React.ForwardRefExoticComponent<
|
84 | React.PropsWithoutRef<LinkProps<TState>> & React.RefAttributes<HTMLAnchorElement>
|
85 | > {}
|
86 |
|
87 | export interface RedirectProps<TState> {
|
88 | from?: string | undefined;
|
89 | to: string;
|
90 | noThrow?: boolean | undefined;
|
91 | state?: TState | undefined;
|
92 | replace?: boolean | undefined;
|
93 | }
|
94 |
|
95 | export class Redirect<TState> extends React.Component<RouteComponentProps<RedirectProps<TState>>> {}
|
96 |
|
97 | export interface MatchProps<TParams> {
|
98 | path: string;
|
99 | children: MatchRenderFn<TParams>;
|
100 | }
|
101 |
|
102 | export type MatchRenderFn<TParams> = (props: MatchRenderProps<TParams>) => React.ReactNode;
|
103 |
|
104 | export interface MatchRenderProps<TParams> {
|
105 | match: null | ({ uri: string; path: string } & TParams);
|
106 | location: WindowLocation;
|
107 | navigate: NavigateFn;
|
108 | }
|
109 |
|
110 | export class Match<TParams> extends React.Component<MatchProps<TParams>> {}
|
111 |
|
112 | export interface NavigateFn {
|
113 | (to: string, options?: NavigateOptions<{}>): Promise<void>;
|
114 | (to: number, options?: undefined): Promise<void>;
|
115 | }
|
116 |
|
117 | export interface NavigateOptions<TState> {
|
118 | state?: TState | undefined;
|
119 | replace?: boolean | undefined;
|
120 | }
|
121 |
|
122 | export interface LocationProps {
|
123 | children: LocationProviderRenderFn;
|
124 | }
|
125 |
|
126 | export class Location extends React.Component<LocationProps> {}
|
127 |
|
128 | export interface LocationProviderProps {
|
129 | history?: History | undefined;
|
130 | children?: React.ReactNode | LocationProviderRenderFn | undefined;
|
131 | }
|
132 |
|
133 | export type LocationProviderRenderFn = (context: LocationContext) => React.ReactNode;
|
134 |
|
135 | export interface LocationContext {
|
136 | location: WindowLocation;
|
137 | navigate: NavigateFn;
|
138 | }
|
139 |
|
140 | export class LocationProvider extends React.Component<LocationProviderProps> {}
|
141 |
|
142 | export interface ServerLocationProps {
|
143 | url: string;
|
144 | }
|
145 |
|
146 | export class ServerLocation extends React.Component<ServerLocationProps> {}
|
147 |
|
148 | export const navigate: NavigateFn;
|
149 |
|
150 | export interface HistorySource {
|
151 | readonly location: WindowLocation;
|
152 | addEventListener(name: string, listener: (event: Event) => void): void;
|
153 | removeEventListener(name: string, listener: (event: Event) => void): void;
|
154 | history: {
|
155 | readonly state: any;
|
156 | pushState(state: any, title: string, uri: string): void;
|
157 | replaceState(state: any, title: string, uri: string): void;
|
158 | };
|
159 | }
|
160 |
|
161 | export function createHistory(source: HistorySource): History;
|
162 |
|
163 | export function createMemorySource(initialPath: string): HistorySource;
|
164 |
|
165 | export interface RedirectRequest {
|
166 | uri: string;
|
167 | }
|
168 |
|
169 | export function isRedirect(error: any): error is RedirectRequest;
|
170 |
|
171 | export function redirectTo(uri: string): void;
|
172 |
|
173 | export const globalHistory: History;
|
174 |
|
175 | export function useLocation(): WindowLocation;
|
176 |
|
177 | export function useNavigate(): NavigateFn;
|
178 |
|
179 |
|
180 |
|
181 | export function useParams<TParams extends { [Param in keyof TParams]?: string } = any>(): TParams;
|
182 |
|
183 | export function useMatch(pathname: string): null | { uri: string; path: string; [param: string]: string };
|