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