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