@tanstack/react-router 0.0.1-beta.57 → 0.0.1-beta.58
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cjs/index.js +5 -4
- package/build/cjs/index.js.map +1 -1
- package/build/esm/index.js +5 -4
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +49 -49
- package/build/types/index.d.ts +22 -22
- package/build/umd/index.development.js +132 -81
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +3 -3
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +48 -56
package/build/stats-react.json
CHANGED
|
@@ -7,31 +7,31 @@
|
|
|
7
7
|
"name": "index.production.js",
|
|
8
8
|
"children": [
|
|
9
9
|
{
|
|
10
|
-
"uid": "
|
|
10
|
+
"uid": "c2ff-99",
|
|
11
11
|
"name": "\u0000rollupPluginBabelHelpers.js"
|
|
12
12
|
},
|
|
13
13
|
{
|
|
14
14
|
"name": "node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
|
|
15
|
-
"uid": "
|
|
15
|
+
"uid": "c2ff-101"
|
|
16
16
|
},
|
|
17
17
|
{
|
|
18
18
|
"name": "packages",
|
|
19
19
|
"children": [
|
|
20
20
|
{
|
|
21
21
|
"name": "store/build/esm/index.js",
|
|
22
|
-
"uid": "
|
|
22
|
+
"uid": "c2ff-103"
|
|
23
23
|
},
|
|
24
24
|
{
|
|
25
25
|
"name": "router/build/esm/index.js",
|
|
26
|
-
"uid": "
|
|
26
|
+
"uid": "c2ff-105"
|
|
27
27
|
},
|
|
28
28
|
{
|
|
29
29
|
"name": "react-store/build/esm/index.js",
|
|
30
|
-
"uid": "
|
|
30
|
+
"uid": "c2ff-107"
|
|
31
31
|
},
|
|
32
32
|
{
|
|
33
33
|
"name": "react-router/src/index.tsx",
|
|
34
|
-
"uid": "
|
|
34
|
+
"uid": "c2ff-109"
|
|
35
35
|
}
|
|
36
36
|
]
|
|
37
37
|
}
|
|
@@ -41,155 +41,155 @@
|
|
|
41
41
|
"isRoot": true
|
|
42
42
|
},
|
|
43
43
|
"nodeParts": {
|
|
44
|
-
"
|
|
44
|
+
"c2ff-99": {
|
|
45
45
|
"renderedLength": 429,
|
|
46
46
|
"gzipLength": 238,
|
|
47
47
|
"brotliLength": 0,
|
|
48
|
-
"mainUid": "
|
|
48
|
+
"mainUid": "c2ff-98"
|
|
49
49
|
},
|
|
50
|
-
"
|
|
50
|
+
"c2ff-101": {
|
|
51
51
|
"renderedLength": 181,
|
|
52
52
|
"gzipLength": 129,
|
|
53
53
|
"brotliLength": 0,
|
|
54
|
-
"mainUid": "
|
|
54
|
+
"mainUid": "c2ff-100"
|
|
55
55
|
},
|
|
56
|
-
"
|
|
56
|
+
"c2ff-103": {
|
|
57
57
|
"renderedLength": 1290,
|
|
58
58
|
"gzipLength": 496,
|
|
59
59
|
"brotliLength": 0,
|
|
60
|
-
"mainUid": "
|
|
60
|
+
"mainUid": "c2ff-102"
|
|
61
61
|
},
|
|
62
|
-
"
|
|
63
|
-
"renderedLength":
|
|
64
|
-
"gzipLength":
|
|
62
|
+
"c2ff-105": {
|
|
63
|
+
"renderedLength": 44621,
|
|
64
|
+
"gzipLength": 10817,
|
|
65
65
|
"brotliLength": 0,
|
|
66
|
-
"mainUid": "
|
|
66
|
+
"mainUid": "c2ff-104"
|
|
67
67
|
},
|
|
68
|
-
"
|
|
68
|
+
"c2ff-107": {
|
|
69
69
|
"renderedLength": 1571,
|
|
70
70
|
"gzipLength": 594,
|
|
71
71
|
"brotliLength": 0,
|
|
72
|
-
"mainUid": "
|
|
72
|
+
"mainUid": "c2ff-106"
|
|
73
73
|
},
|
|
74
|
-
"
|
|
75
|
-
"renderedLength":
|
|
74
|
+
"c2ff-109": {
|
|
75
|
+
"renderedLength": 11729,
|
|
76
76
|
"gzipLength": 3116,
|
|
77
77
|
"brotliLength": 0,
|
|
78
|
-
"mainUid": "
|
|
78
|
+
"mainUid": "c2ff-108"
|
|
79
79
|
}
|
|
80
80
|
},
|
|
81
81
|
"nodeMetas": {
|
|
82
|
-
"
|
|
82
|
+
"c2ff-98": {
|
|
83
83
|
"id": "\u0000rollupPluginBabelHelpers.js",
|
|
84
84
|
"moduleParts": {
|
|
85
|
-
"index.production.js": "
|
|
85
|
+
"index.production.js": "c2ff-99"
|
|
86
86
|
},
|
|
87
87
|
"imported": [],
|
|
88
88
|
"importedBy": [
|
|
89
89
|
{
|
|
90
|
-
"uid": "
|
|
90
|
+
"uid": "c2ff-108"
|
|
91
91
|
}
|
|
92
92
|
]
|
|
93
93
|
},
|
|
94
|
-
"
|
|
94
|
+
"c2ff-100": {
|
|
95
95
|
"id": "/node_modules/.pnpm/tiny-invariant@1.3.1/node_modules/tiny-invariant/dist/esm/tiny-invariant.js",
|
|
96
96
|
"moduleParts": {
|
|
97
|
-
"index.production.js": "
|
|
97
|
+
"index.production.js": "c2ff-101"
|
|
98
98
|
},
|
|
99
99
|
"imported": [],
|
|
100
100
|
"importedBy": [
|
|
101
101
|
{
|
|
102
|
-
"uid": "
|
|
102
|
+
"uid": "c2ff-104"
|
|
103
103
|
}
|
|
104
104
|
]
|
|
105
105
|
},
|
|
106
|
-
"
|
|
106
|
+
"c2ff-102": {
|
|
107
107
|
"id": "/packages/store/build/esm/index.js",
|
|
108
108
|
"moduleParts": {
|
|
109
|
-
"index.production.js": "
|
|
109
|
+
"index.production.js": "c2ff-103"
|
|
110
110
|
},
|
|
111
111
|
"imported": [],
|
|
112
112
|
"importedBy": [
|
|
113
113
|
{
|
|
114
|
-
"uid": "
|
|
114
|
+
"uid": "c2ff-104"
|
|
115
115
|
}
|
|
116
116
|
]
|
|
117
117
|
},
|
|
118
|
-
"
|
|
118
|
+
"c2ff-104": {
|
|
119
119
|
"id": "/packages/router/build/esm/index.js",
|
|
120
120
|
"moduleParts": {
|
|
121
|
-
"index.production.js": "
|
|
121
|
+
"index.production.js": "c2ff-105"
|
|
122
122
|
},
|
|
123
123
|
"imported": [
|
|
124
124
|
{
|
|
125
|
-
"uid": "
|
|
125
|
+
"uid": "c2ff-100"
|
|
126
126
|
},
|
|
127
127
|
{
|
|
128
|
-
"uid": "
|
|
128
|
+
"uid": "c2ff-102"
|
|
129
129
|
}
|
|
130
130
|
],
|
|
131
131
|
"importedBy": [
|
|
132
132
|
{
|
|
133
|
-
"uid": "
|
|
133
|
+
"uid": "c2ff-108"
|
|
134
134
|
}
|
|
135
135
|
]
|
|
136
136
|
},
|
|
137
|
-
"
|
|
137
|
+
"c2ff-106": {
|
|
138
138
|
"id": "/packages/react-store/build/esm/index.js",
|
|
139
139
|
"moduleParts": {
|
|
140
|
-
"index.production.js": "
|
|
140
|
+
"index.production.js": "c2ff-107"
|
|
141
141
|
},
|
|
142
142
|
"imported": [
|
|
143
143
|
{
|
|
144
|
-
"uid": "
|
|
144
|
+
"uid": "c2ff-111"
|
|
145
145
|
}
|
|
146
146
|
],
|
|
147
147
|
"importedBy": [
|
|
148
148
|
{
|
|
149
|
-
"uid": "
|
|
149
|
+
"uid": "c2ff-108"
|
|
150
150
|
}
|
|
151
151
|
]
|
|
152
152
|
},
|
|
153
|
-
"
|
|
153
|
+
"c2ff-108": {
|
|
154
154
|
"id": "/packages/react-router/src/index.tsx",
|
|
155
155
|
"moduleParts": {
|
|
156
|
-
"index.production.js": "
|
|
156
|
+
"index.production.js": "c2ff-109"
|
|
157
157
|
},
|
|
158
158
|
"imported": [
|
|
159
159
|
{
|
|
160
|
-
"uid": "
|
|
160
|
+
"uid": "c2ff-98"
|
|
161
161
|
},
|
|
162
162
|
{
|
|
163
|
-
"uid": "
|
|
163
|
+
"uid": "c2ff-110"
|
|
164
164
|
},
|
|
165
165
|
{
|
|
166
|
-
"uid": "
|
|
166
|
+
"uid": "c2ff-104"
|
|
167
167
|
},
|
|
168
168
|
{
|
|
169
|
-
"uid": "
|
|
169
|
+
"uid": "c2ff-106"
|
|
170
170
|
}
|
|
171
171
|
],
|
|
172
172
|
"importedBy": [],
|
|
173
173
|
"isEntry": true
|
|
174
174
|
},
|
|
175
|
-
"
|
|
175
|
+
"c2ff-110": {
|
|
176
176
|
"id": "react",
|
|
177
177
|
"moduleParts": {},
|
|
178
178
|
"imported": [],
|
|
179
179
|
"importedBy": [
|
|
180
180
|
{
|
|
181
|
-
"uid": "
|
|
181
|
+
"uid": "c2ff-108"
|
|
182
182
|
}
|
|
183
183
|
],
|
|
184
184
|
"isExternal": true
|
|
185
185
|
},
|
|
186
|
-
"
|
|
186
|
+
"c2ff-111": {
|
|
187
187
|
"id": "use-sync-external-store/shim/with-selector",
|
|
188
188
|
"moduleParts": {},
|
|
189
189
|
"imported": [],
|
|
190
190
|
"importedBy": [
|
|
191
191
|
{
|
|
192
|
-
"uid": "
|
|
192
|
+
"uid": "c2ff-106"
|
|
193
193
|
}
|
|
194
194
|
],
|
|
195
195
|
"isExternal": true
|
package/build/types/index.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* @license MIT
|
|
10
10
|
*/
|
|
11
11
|
import * as React from 'react';
|
|
12
|
-
import {
|
|
12
|
+
import { RegisteredRoutesInfo, LinkOptions, ToOptions, MatchRouteOptions, RouteByPath, ResolveRelativePath, NoInfer, ValidFromPath, RegisteredRouter, AnyRoute, Route, AnyRoutesInfo, RoutesInfo, Router, RouterOptions, DefaultRoutesInfo, RouterStore, RouteMatch, Expand } from '@tanstack/router';
|
|
13
13
|
export * from '@tanstack/router';
|
|
14
14
|
export { useStore } from '@tanstack/react-store';
|
|
15
15
|
|
|
@@ -21,16 +21,16 @@ type RouteComponent<TProps = {}> = SyncRouteComponent<TProps> & {
|
|
|
21
21
|
declare function lazy(importer: () => Promise<{
|
|
22
22
|
default: SyncRouteComponent;
|
|
23
23
|
}>): RouteComponent;
|
|
24
|
-
type LinkPropsOptions<TFrom extends
|
|
24
|
+
type LinkPropsOptions<TFrom extends RegisteredRoutesInfo['routePaths'] = '/', TTo extends string = '.'> = LinkOptions<RegisteredRoutesInfo, TFrom, TTo> & {
|
|
25
25
|
activeProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
26
26
|
inactiveProps?: React.AnchorHTMLAttributes<HTMLAnchorElement> | (() => React.AnchorHTMLAttributes<HTMLAnchorElement>);
|
|
27
27
|
};
|
|
28
|
-
type MakeUseMatchRouteOptions<TFrom extends
|
|
29
|
-
type MakeMatchRouteOptions<TFrom extends
|
|
30
|
-
children?: ReactNode | ((params:
|
|
28
|
+
type MakeUseMatchRouteOptions<TFrom extends RegisteredRoutesInfo['routePaths'] = '/', TTo extends string = '.'> = ToOptions<RegisteredRoutesInfo, TFrom, TTo> & MatchRouteOptions;
|
|
29
|
+
type MakeMatchRouteOptions<TFrom extends RegisteredRoutesInfo['routePaths'] = '/', TTo extends string = '.'> = ToOptions<RegisteredRoutesInfo, TFrom, TTo> & MatchRouteOptions & {
|
|
30
|
+
children?: ReactNode | ((params: RouteByPath<RegisteredRoutesInfo, ResolveRelativePath<TFrom, NoInfer<TTo>>>['__types']['allParams']) => ReactNode);
|
|
31
31
|
};
|
|
32
|
-
type MakeLinkPropsOptions<TFrom extends ValidFromPath<
|
|
33
|
-
type MakeLinkOptions<TFrom extends
|
|
32
|
+
type MakeLinkPropsOptions<TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/', TTo extends string = '.'> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
33
|
+
type MakeLinkOptions<TFrom extends RegisteredRoutesInfo['routePaths'] = '/', TTo extends string = '.'> = LinkPropsOptions<TFrom, TTo> & React.AnchorHTMLAttributes<HTMLAnchorElement> & Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'children'> & {
|
|
34
34
|
children?: ReactNode | ((state: {
|
|
35
35
|
isActive: boolean;
|
|
36
36
|
}) => ReactNode);
|
|
@@ -45,7 +45,7 @@ declare module '@tanstack/router' {
|
|
|
45
45
|
};
|
|
46
46
|
}>;
|
|
47
47
|
}
|
|
48
|
-
interface RouterOptions<
|
|
48
|
+
interface RouterOptions<TRouteTree, TRouterContext> {
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
type PromptProps = {
|
|
@@ -53,9 +53,9 @@ type PromptProps = {
|
|
|
53
53
|
when?: boolean | any;
|
|
54
54
|
children?: ReactNode;
|
|
55
55
|
};
|
|
56
|
-
declare function useLinkProps<TFrom extends ValidFromPath<
|
|
57
|
-
interface LinkFn<TDefaultFrom extends
|
|
58
|
-
<TFrom extends
|
|
56
|
+
declare function useLinkProps<TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/', TTo extends string = '.'>(options: MakeLinkPropsOptions<TFrom, TTo>): React.AnchorHTMLAttributes<HTMLAnchorElement>;
|
|
57
|
+
interface LinkFn<TDefaultFrom extends RegisteredRoutesInfo['routePaths'] = '/', TDefaultTo extends string = '.'> {
|
|
58
|
+
<TFrom extends RegisteredRoutesInfo['routePaths'] = TDefaultFrom, TTo extends string = TDefaultTo>(props: MakeLinkOptions<TFrom, TTo> & React.RefAttributes<HTMLAnchorElement>): ReactNode;
|
|
59
59
|
}
|
|
60
60
|
declare const Link: LinkFn;
|
|
61
61
|
type MatchesContextValue = RouteMatch[];
|
|
@@ -67,37 +67,37 @@ type MatchesProviderProps = {
|
|
|
67
67
|
value: MatchesContextValue;
|
|
68
68
|
children: ReactNode;
|
|
69
69
|
};
|
|
70
|
-
declare class ReactRouter<TRouteConfig extends
|
|
70
|
+
declare class ReactRouter<TRouteConfig extends AnyRoute = Route, TRoutesInfo extends AnyRoutesInfo = RoutesInfo<TRouteConfig>, TRouterContext = unknown> extends Router<TRouteConfig, TRoutesInfo, TRouterContext> {
|
|
71
71
|
constructor(opts: RouterOptions<TRouteConfig, TRouterContext>);
|
|
72
72
|
}
|
|
73
|
-
type RouterProps<TRouteConfig extends
|
|
74
|
-
router: Router<TRouteConfig,
|
|
73
|
+
type RouterProps<TRouteConfig extends AnyRoute = Route, TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo, TRouterContext = unknown> = RouterOptions<TRouteConfig, TRouterContext> & {
|
|
74
|
+
router: Router<TRouteConfig, TRoutesInfo, TRouterContext>;
|
|
75
75
|
};
|
|
76
|
-
declare function RouterProvider<TRouteConfig extends
|
|
76
|
+
declare function RouterProvider<TRouteConfig extends AnyRoute = Route, TRoutesInfo extends AnyRoutesInfo = DefaultRoutesInfo, TRouterContext = unknown>({ router, ...rest }: RouterProps<TRouteConfig, TRoutesInfo, TRouterContext>): JSX.Element;
|
|
77
77
|
declare function useRouter(): RegisteredRouter;
|
|
78
78
|
declare function useRouterStore<T = RouterStore>(selector?: (state: Router['store']) => T, shallow?: boolean): T;
|
|
79
79
|
declare function useMatches(): RouteMatch[];
|
|
80
|
-
declare function useMatch<TFrom extends keyof
|
|
80
|
+
declare function useMatch<TFrom extends keyof RegisteredRoutesInfo['routesById'], TStrict extends boolean = true, TRouteMatch = RouteMatch<RegisteredRoutesInfo, RegisteredRoutesInfo['routesById'][TFrom]>>(opts?: {
|
|
81
81
|
from: TFrom;
|
|
82
82
|
strict?: TStrict;
|
|
83
83
|
track?: (match: TRouteMatch) => any;
|
|
84
84
|
shallow?: boolean;
|
|
85
85
|
}): TStrict extends true ? TRouteMatch : TRouteMatch | undefined;
|
|
86
|
-
declare function useRoute<TId extends keyof
|
|
87
|
-
declare function useSearch<TFrom extends keyof
|
|
86
|
+
declare function useRoute<TId extends keyof RegisteredRoutesInfo['routesById'] = '/'>(routeId: TId): RegisteredRoutesInfo['routesById'][TId];
|
|
87
|
+
declare function useSearch<TFrom extends keyof RegisteredRoutesInfo['routesById'], TStrict extends boolean = true, TSearch = RegisteredRoutesInfo['routesById'][TFrom]['__types']['fullSearchSchema'], TSelected = TSearch>(opts?: {
|
|
88
88
|
from: TFrom;
|
|
89
89
|
strict?: TStrict;
|
|
90
90
|
track?: (search: TSearch) => TSelected;
|
|
91
91
|
}): TStrict extends true ? TSelected : TSelected | undefined;
|
|
92
|
-
declare function useParams<TFrom extends keyof
|
|
92
|
+
declare function useParams<TFrom extends keyof RegisteredRoutesInfo['routesById'] = '/', TDefaultSelected = Expand<RegisteredRoutesInfo['allParams'] & RegisteredRoutesInfo['routesById'][TFrom]['__types']['allParams']>, TSelected = TDefaultSelected>(opts?: {
|
|
93
93
|
from: TFrom;
|
|
94
94
|
track?: (search: TDefaultSelected) => TSelected;
|
|
95
95
|
}): TSelected;
|
|
96
|
-
declare function useNavigate<TDefaultFrom extends keyof
|
|
96
|
+
declare function useNavigate<TDefaultFrom extends keyof RegisteredRoutesInfo['routesById'] = '/'>(defaultOpts?: {
|
|
97
97
|
from?: TDefaultFrom;
|
|
98
98
|
}): <TFrom extends string = TDefaultFrom, TTo extends string = ".">(opts?: MakeLinkOptions<TFrom, TTo> | undefined) => Promise<void>;
|
|
99
|
-
declare function useMatchRoute(): <TFrom extends ValidFromPath<
|
|
100
|
-
declare function MatchRoute<TFrom extends ValidFromPath<
|
|
99
|
+
declare function useMatchRoute(): <TFrom extends ValidFromPath<AnyRoutesInfo> = "/", TTo extends string = ".">(opts: MakeUseMatchRouteOptions<TFrom, TTo>) => any;
|
|
100
|
+
declare function MatchRoute<TFrom extends ValidFromPath<RegisteredRoutesInfo> = '/', TTo extends string = '.'>(props: MakeMatchRouteOptions<TFrom, TTo>): any;
|
|
101
101
|
declare function Outlet(): JSX.Element | null;
|
|
102
102
|
declare function DefaultErrorBoundary({ error }: {
|
|
103
103
|
error: any;
|
|
@@ -565,62 +565,110 @@
|
|
|
565
565
|
return out;
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
+
const rootRouteId = '__root__';
|
|
568
569
|
class Route {
|
|
569
|
-
|
|
570
|
-
Object.assign(this, {
|
|
571
|
-
...routeConfig,
|
|
572
|
-
originalIndex,
|
|
573
|
-
options,
|
|
574
|
-
getRouter: () => router,
|
|
575
|
-
childRoutes: undefined,
|
|
576
|
-
getParentRoute: () => parent
|
|
577
|
-
});
|
|
578
|
-
router.options.createRoute?.({
|
|
579
|
-
router,
|
|
580
|
-
route: this
|
|
581
|
-
});
|
|
582
|
-
}
|
|
583
|
-
}
|
|
570
|
+
// Set up in this.init()
|
|
584
571
|
|
|
585
|
-
|
|
586
|
-
const createRouteConfig = (options = {}, children = [], isRoot = true, parentId, parentPath) => {
|
|
587
|
-
if (isRoot) {
|
|
588
|
-
options.path = rootRouteId;
|
|
589
|
-
}
|
|
572
|
+
// customId!: TCustomId
|
|
590
573
|
|
|
591
|
-
//
|
|
592
|
-
if (parentId === rootRouteId) {
|
|
593
|
-
parentId = '';
|
|
594
|
-
}
|
|
595
|
-
let path = isRoot ? rootRouteId : options.path;
|
|
574
|
+
// Optional
|
|
596
575
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
}
|
|
601
|
-
const routeId = path || options.id;
|
|
602
|
-
let id = joinPaths([parentId, routeId]);
|
|
603
|
-
if (path === rootRouteId) {
|
|
604
|
-
path = '/';
|
|
605
|
-
}
|
|
606
|
-
if (id !== rootRouteId) {
|
|
607
|
-
id = joinPaths(['/', id]);
|
|
576
|
+
constructor(options) {
|
|
577
|
+
this.options = options || {};
|
|
578
|
+
this.isRoot = !options?.getParentRoute;
|
|
608
579
|
}
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
580
|
+
init = () => {
|
|
581
|
+
const allOptions = this.options;
|
|
582
|
+
const isRoot = !allOptions?.path && !allOptions?.id;
|
|
583
|
+
const parent = this.options?.getParentRoute?.();
|
|
584
|
+
if (isRoot) {
|
|
585
|
+
this.path = rootRouteId;
|
|
586
|
+
} else {
|
|
587
|
+
invariant(parent, `Child Route instances must pass a 'getParentRoute: () => ParentRoute' option that returns a Route instance.`);
|
|
588
|
+
}
|
|
589
|
+
let path = isRoot ? rootRouteId : allOptions.path;
|
|
590
|
+
|
|
591
|
+
// If the path is anything other than an index path, trim it up
|
|
592
|
+
if (path && path !== '/') {
|
|
593
|
+
path = trimPath(path);
|
|
594
|
+
}
|
|
595
|
+
const customId = allOptions?.id || path;
|
|
596
|
+
|
|
597
|
+
// Strip the parentId prefix from the first level of children
|
|
598
|
+
let id = isRoot ? rootRouteId : joinPaths([parent.id === rootRouteId ? '' : parent.id, customId]);
|
|
599
|
+
if (path === rootRouteId) {
|
|
600
|
+
path = '/';
|
|
621
601
|
}
|
|
602
|
+
if (id !== rootRouteId) {
|
|
603
|
+
id = joinPaths(['/', id]);
|
|
604
|
+
}
|
|
605
|
+
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parent.fullPath, path]));
|
|
606
|
+
this.id = id;
|
|
607
|
+
// this.customId = customId as TCustomId
|
|
608
|
+
this.fullPath = fullPath;
|
|
622
609
|
};
|
|
623
|
-
|
|
610
|
+
addChildren = children => {
|
|
611
|
+
this.children = children;
|
|
612
|
+
return this;
|
|
613
|
+
};
|
|
614
|
+
|
|
615
|
+
// generate: () => {
|
|
616
|
+
// invariant(
|
|
617
|
+
// false,
|
|
618
|
+
// `routeConfig.generate() is used by TanStack Router's file-based routing code generation and should not actually be called during runtime. `,
|
|
619
|
+
// )
|
|
620
|
+
// },
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
class RootRoute extends Route {
|
|
624
|
+
constructor(options) {
|
|
625
|
+
super(options);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
// const rootRoute = new RootRoute({
|
|
630
|
+
// validateSearch: () => null as unknown as { root?: boolean },
|
|
631
|
+
// })
|
|
632
|
+
|
|
633
|
+
// const aRoute = new Route({
|
|
634
|
+
// getParentRoute: () => rootRoute,
|
|
635
|
+
// path: 'a',
|
|
636
|
+
// validateSearch: () => null as unknown as { a?: string },
|
|
637
|
+
// })
|
|
638
|
+
|
|
639
|
+
// const bRoute = new Route({
|
|
640
|
+
// getParentRoute: () => aRoute,
|
|
641
|
+
// path: 'b',
|
|
642
|
+
// })
|
|
643
|
+
|
|
644
|
+
// const rootIsRoot = rootRoute.isRoot
|
|
645
|
+
// // ^?
|
|
646
|
+
// const aIsRoot = aRoute.isRoot
|
|
647
|
+
// // ^?
|
|
648
|
+
|
|
649
|
+
// const rId = rootRoute.id
|
|
650
|
+
// // ^?
|
|
651
|
+
// const aId = aRoute.id
|
|
652
|
+
// // ^?
|
|
653
|
+
// const bId = bRoute.id
|
|
654
|
+
// // ^?
|
|
655
|
+
|
|
656
|
+
// const rPath = rootRoute.fullPath
|
|
657
|
+
// // ^?
|
|
658
|
+
// const aPath = aRoute.fullPath
|
|
659
|
+
// // ^?
|
|
660
|
+
// const bPath = bRoute.fullPath
|
|
661
|
+
// // ^?
|
|
662
|
+
|
|
663
|
+
// const rSearch = rootRoute.__types.fullSearchSchema
|
|
664
|
+
// // ^?
|
|
665
|
+
// const aSearch = aRoute.__types.fullSearchSchema
|
|
666
|
+
// // ^?
|
|
667
|
+
// const bSearch = bRoute.__types.fullSearchSchema
|
|
668
|
+
// // ^?
|
|
669
|
+
|
|
670
|
+
// const config = rootRoute.addChildren([aRoute.addChildren([bRoute])])
|
|
671
|
+
// // ^?
|
|
624
672
|
|
|
625
673
|
//
|
|
626
674
|
|
|
@@ -909,12 +957,12 @@
|
|
|
909
957
|
}
|
|
910
958
|
const {
|
|
911
959
|
basepath,
|
|
912
|
-
|
|
960
|
+
routeTree
|
|
913
961
|
} = this.options;
|
|
914
962
|
this.basepath = `/${trimPath(basepath ?? '') ?? ''}`;
|
|
915
|
-
if (
|
|
963
|
+
if (routeTree) {
|
|
916
964
|
this.routesById = {};
|
|
917
|
-
this.routeTree = this.#buildRouteTree(
|
|
965
|
+
this.routeTree = this.#buildRouteTree(routeTree);
|
|
918
966
|
}
|
|
919
967
|
return this;
|
|
920
968
|
};
|
|
@@ -1057,17 +1105,18 @@
|
|
|
1057
1105
|
return matches;
|
|
1058
1106
|
}
|
|
1059
1107
|
const existingMatches = [...this.store.state.currentMatches, ...(this.store.state.pendingMatches ?? [])];
|
|
1060
|
-
const
|
|
1108
|
+
const findInRouteTree = async routes => {
|
|
1061
1109
|
const parentMatch = last(matches);
|
|
1062
1110
|
let params = parentMatch?.params ?? {};
|
|
1063
1111
|
const filteredRoutes = this.options.filterRoutes?.(routes) ?? routes;
|
|
1064
|
-
let
|
|
1112
|
+
let matchingRoutes = [];
|
|
1065
1113
|
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
1066
1114
|
routes.some(route => {
|
|
1067
|
-
|
|
1068
|
-
|
|
1115
|
+
const children = route.children;
|
|
1116
|
+
if (!route.path && children?.length) {
|
|
1117
|
+
return findMatchInRoutes([...matchingRoutes, route], children);
|
|
1069
1118
|
}
|
|
1070
|
-
const fuzzy =
|
|
1119
|
+
const fuzzy = route.path === '/' ? false : !!children?.length;
|
|
1071
1120
|
const matchParams = matchPathname(this.basepath, pathname, {
|
|
1072
1121
|
to: route.fullPath,
|
|
1073
1122
|
fuzzy,
|
|
@@ -1088,17 +1137,17 @@
|
|
|
1088
1137
|
};
|
|
1089
1138
|
}
|
|
1090
1139
|
if (!!matchParams) {
|
|
1091
|
-
|
|
1140
|
+
matchingRoutes = [...parentRoutes, route];
|
|
1092
1141
|
}
|
|
1093
|
-
return !!
|
|
1142
|
+
return !!matchingRoutes.length;
|
|
1094
1143
|
});
|
|
1095
|
-
return !!
|
|
1144
|
+
return !!matchingRoutes.length;
|
|
1096
1145
|
};
|
|
1097
1146
|
findMatchInRoutes([], filteredRoutes);
|
|
1098
|
-
if (!
|
|
1147
|
+
if (!matchingRoutes.length) {
|
|
1099
1148
|
return;
|
|
1100
1149
|
}
|
|
1101
|
-
|
|
1150
|
+
matchingRoutes.forEach(foundRoute => {
|
|
1102
1151
|
const interpolatedPath = interpolatePath(foundRoute.path, params);
|
|
1103
1152
|
const matchId = interpolatePath(foundRoute.id, params, true);
|
|
1104
1153
|
const match = existingMatches.find(d => d.id === matchId) ||
|
|
@@ -1110,12 +1159,13 @@
|
|
|
1110
1159
|
});
|
|
1111
1160
|
matches.push(match);
|
|
1112
1161
|
});
|
|
1113
|
-
const foundRoute = last(
|
|
1114
|
-
|
|
1115
|
-
|
|
1162
|
+
const foundRoute = last(matchingRoutes);
|
|
1163
|
+
const foundChildren = foundRoute.children;
|
|
1164
|
+
if (foundChildren?.length) {
|
|
1165
|
+
findInRouteTree(foundChildren);
|
|
1116
1166
|
}
|
|
1117
1167
|
};
|
|
1118
|
-
|
|
1168
|
+
findInRouteTree([this.routeTree]);
|
|
1119
1169
|
linkMatches(matches);
|
|
1120
1170
|
return matches;
|
|
1121
1171
|
};
|
|
@@ -1362,11 +1412,12 @@
|
|
|
1362
1412
|
};
|
|
1363
1413
|
});
|
|
1364
1414
|
};
|
|
1365
|
-
#buildRouteTree =
|
|
1366
|
-
const recurseRoutes =
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1415
|
+
#buildRouteTree = routeTree => {
|
|
1416
|
+
const recurseRoutes = routes => {
|
|
1417
|
+
routes.forEach((route, i) => {
|
|
1418
|
+
route.init();
|
|
1419
|
+
route.originalIndex = i;
|
|
1420
|
+
route.router = this;
|
|
1370
1421
|
const existingRoute = this.routesById[route.id];
|
|
1371
1422
|
if (existingRoute) {
|
|
1372
1423
|
{
|
|
@@ -1375,13 +1426,12 @@
|
|
|
1375
1426
|
throw new Error();
|
|
1376
1427
|
}
|
|
1377
1428
|
this.routesById[route.id] = route;
|
|
1378
|
-
const children =
|
|
1379
|
-
|
|
1380
|
-
return route;
|
|
1429
|
+
const children = route.children;
|
|
1430
|
+
if (children?.length) recurseRoutes(children);
|
|
1381
1431
|
});
|
|
1382
1432
|
};
|
|
1383
|
-
|
|
1384
|
-
return
|
|
1433
|
+
recurseRoutes([routeTree]);
|
|
1434
|
+
return routeTree;
|
|
1385
1435
|
};
|
|
1386
1436
|
#parseLocation = previousLocation => {
|
|
1387
1437
|
let {
|
|
@@ -1842,6 +1892,11 @@
|
|
|
1842
1892
|
match: match
|
|
1843
1893
|
}))));
|
|
1844
1894
|
}
|
|
1895
|
+
|
|
1896
|
+
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
1897
|
+
// there has to be a better way to reset error boundaries when the
|
|
1898
|
+
// router's location key changes.
|
|
1899
|
+
|
|
1845
1900
|
class CatchBoundary extends React__namespace.Component {
|
|
1846
1901
|
state = {
|
|
1847
1902
|
error: false,
|
|
@@ -1862,10 +1917,6 @@
|
|
|
1862
1917
|
}));
|
|
1863
1918
|
}
|
|
1864
1919
|
}
|
|
1865
|
-
|
|
1866
|
-
// This is the messiest thing ever... I'm either seriously tired (likely) or
|
|
1867
|
-
// there has to be a better way to reset error boundaries when the
|
|
1868
|
-
// router's location key changes.
|
|
1869
1920
|
function CatchBoundaryInner(props) {
|
|
1870
1921
|
const [activeErrorState, setActiveErrorState] = React__namespace.useState(props.errorState);
|
|
1871
1922
|
const router = useRouter();
|
|
@@ -1949,6 +2000,7 @@
|
|
|
1949
2000
|
exports.MatchRoute = MatchRoute;
|
|
1950
2001
|
exports.Outlet = Outlet;
|
|
1951
2002
|
exports.ReactRouter = ReactRouter;
|
|
2003
|
+
exports.RootRoute = RootRoute;
|
|
1952
2004
|
exports.Route = Route;
|
|
1953
2005
|
exports.RouteMatch = RouteMatch;
|
|
1954
2006
|
exports.Router = Router;
|
|
@@ -1957,7 +2009,6 @@
|
|
|
1957
2009
|
exports.createBrowserHistory = createBrowserHistory;
|
|
1958
2010
|
exports.createHashHistory = createHashHistory;
|
|
1959
2011
|
exports.createMemoryHistory = createMemoryHistory;
|
|
1960
|
-
exports.createRouteConfig = createRouteConfig;
|
|
1961
2012
|
exports.decode = decode;
|
|
1962
2013
|
exports.defaultFetchServerDataFn = defaultFetchServerDataFn;
|
|
1963
2014
|
exports.defaultParseSearch = defaultParseSearch;
|