1 |
|
2 | import type { Location, Path, To } from "history";
|
3 | export declare function invariant(cond: any, message: string): asserts cond;
|
4 | export declare function warning(cond: any, message: string): void;
|
5 | export declare function warningOnce(key: string, cond: boolean, message: string): void;
|
6 | declare type ParamParseFailed = {
|
7 | failed: true;
|
8 | };
|
9 | declare type ParamParseSegment<Segment extends string> = Segment extends `${infer LeftSegment}/${infer RightSegment}` ? ParamParseSegment<LeftSegment> extends infer LeftResult ? ParamParseSegment<RightSegment> extends infer RightResult ? LeftResult extends string ? RightResult extends string ? LeftResult | RightResult : LeftResult : RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : ParamParseSegment<RightSegment> extends infer RightResult ? RightResult extends string ? RightResult : ParamParseFailed : ParamParseFailed : Segment extends `:${infer Remaining}` ? Remaining : ParamParseFailed;
|
10 | export declare type ParamParseKey<Segment extends string> = ParamParseSegment<Segment> extends string ? ParamParseSegment<Segment> : string;
|
11 |
|
12 |
|
13 |
|
14 | export declare type Params<Key extends string = string> = {
|
15 | readonly [key in Key]: string | undefined;
|
16 | };
|
17 |
|
18 |
|
19 |
|
20 |
|
21 | export interface RouteObject {
|
22 | caseSensitive?: boolean;
|
23 | children?: RouteObject[];
|
24 | element?: React.ReactNode;
|
25 | index?: boolean;
|
26 | path?: string;
|
27 | }
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 | export declare function generatePath(path: string, params?: Params): string;
|
34 |
|
35 |
|
36 |
|
37 | export interface RouteMatch<ParamKey extends string = string> {
|
38 | |
39 |
|
40 |
|
41 | params: Params<ParamKey>;
|
42 | |
43 |
|
44 |
|
45 | pathname: string;
|
46 | |
47 |
|
48 |
|
49 | pathnameBase: string;
|
50 | |
51 |
|
52 |
|
53 | route: RouteObject;
|
54 | }
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | export declare function matchRoutes(routes: RouteObject[], locationArg: Partial<Location> | string, basename?: string): RouteMatch[] | null;
|
61 |
|
62 |
|
63 |
|
64 | export interface PathPattern<Path extends string = string> {
|
65 | |
66 |
|
67 |
|
68 |
|
69 |
|
70 | path: Path;
|
71 | |
72 |
|
73 |
|
74 |
|
75 | caseSensitive?: boolean;
|
76 | |
77 |
|
78 |
|
79 | end?: boolean;
|
80 | }
|
81 |
|
82 |
|
83 |
|
84 | export interface PathMatch<ParamKey extends string = string> {
|
85 | |
86 |
|
87 |
|
88 | params: Params<ParamKey>;
|
89 | |
90 |
|
91 |
|
92 | pathname: string;
|
93 | |
94 |
|
95 |
|
96 | pathnameBase: string;
|
97 | |
98 |
|
99 |
|
100 | pattern: PathPattern;
|
101 | }
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | export declare function matchPath<ParamKey extends ParamParseKey<Path>, Path extends string>(pattern: PathPattern<Path> | Path, pathname: string): PathMatch<ParamKey> | null;
|
109 |
|
110 |
|
111 |
|
112 |
|
113 |
|
114 | export declare function resolvePath(to: To, fromPathname?: string): Path;
|
115 | export declare function resolveTo(toArg: To, routePathnames: string[], locationPathname: string): Path;
|
116 | export declare function getToPathname(to: To): string | undefined;
|
117 | export declare function stripBasename(pathname: string, basename: string): string | null;
|
118 | export declare const joinPaths: (paths: string[]) => string;
|
119 | export declare const normalizePathname: (pathname: string) => string;
|
120 | export {};
|