1 | import * as React from "react";
|
2 | import * as url from "url";
|
3 |
|
4 | type UrlLike = url.UrlObject | url.Url;
|
5 |
|
6 | export interface EventChangeOptions {
|
7 | shallow?: boolean;
|
8 | [key: string]: any;
|
9 | }
|
10 |
|
11 | export type PopStateCallback = (state: any) => boolean | undefined;
|
12 |
|
13 | export type RouterCallback = () => void;
|
14 | export interface RouterProps {
|
15 |
|
16 | readonly pathname: string;
|
17 | readonly route: string;
|
18 | readonly asPath?: string;
|
19 | readonly query?: {
|
20 | [key: string]:
|
21 | | boolean
|
22 | | boolean[]
|
23 | | number
|
24 | | number[]
|
25 | | string
|
26 | | string[];
|
27 | };
|
28 |
|
29 |
|
30 | readonly components: {
|
31 | [key: string]: { Component: React.ComponentType<any>; err: any };
|
32 | };
|
33 |
|
34 |
|
35 | back(): void;
|
36 | beforePopState(cb: PopStateCallback): boolean;
|
37 | prefetch(url: string): Promise<React.ComponentType<any>>;
|
38 | push(
|
39 | url: string | UrlLike,
|
40 | as?: string | UrlLike,
|
41 | options?: EventChangeOptions,
|
42 | ): Promise<boolean>;
|
43 | reload(route: string): Promise<void>;
|
44 | replace(
|
45 | url: string | UrlLike,
|
46 | as?: string | UrlLike,
|
47 | options?: EventChangeOptions,
|
48 | ): Promise<boolean>;
|
49 |
|
50 |
|
51 | onAppUpdated?(nextRoute: string): void;
|
52 | onBeforeHistoryChange?(as: string): void;
|
53 | onHashChangeStart?(url: string): void;
|
54 | onHashChangeComplete?(url: string): void;
|
55 | onRouteChangeComplete?(url: string): void;
|
56 | onRouteChangeError?(error: any, url: string): void;
|
57 | onRouteChangeStart?(url: string): void;
|
58 | }
|
59 |
|
60 | export interface SingletonRouter extends RouterProps {
|
61 | router: RouterProps | null;
|
62 | readyCallbacks: RouterCallback[];
|
63 | ready(cb: RouterCallback): void;
|
64 | }
|
65 |
|
66 | export interface WithRouterProps {
|
67 | router: SingletonRouter;
|
68 | }
|
69 |
|
70 | export function withRouter<T extends {}>(
|
71 | Component: React.ComponentType<T & WithRouterProps>,
|
72 | ): React.ComponentType<T>;
|
73 |
|
74 | declare const Router: SingletonRouter;
|
75 | export default Router;
|