@tanstack/router-core 0.0.1-beta.25 → 0.0.1-beta.29
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/_virtual/_rollupPluginBabelHelpers.js +0 -2
- package/build/cjs/_virtual/_rollupPluginBabelHelpers.js.map +1 -1
- package/build/cjs/{packages/router-core/src/index.js → index.js} +22 -6
- package/build/cjs/{packages/router-core/src/index.js.map → index.js.map} +1 -1
- package/build/cjs/{packages/router-core/src/path.js → path.js} +6 -30
- package/build/cjs/path.js.map +1 -0
- package/build/cjs/{packages/router-core/src/qss.js → qss.js} +8 -13
- package/build/cjs/qss.js.map +1 -0
- package/build/cjs/{packages/router-core/src/route.js → route.js} +7 -16
- package/build/cjs/route.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeConfig.js → routeConfig.js} +13 -12
- package/build/cjs/routeConfig.js.map +1 -0
- package/build/cjs/{packages/router-core/src/routeMatch.js → routeMatch.js} +15 -35
- package/build/cjs/routeMatch.js.map +1 -0
- package/build/cjs/{packages/router-core/src/router.js → router.js} +103 -159
- package/build/cjs/router.js.map +1 -0
- package/build/cjs/{packages/router-core/src/searchParams.js → searchParams.js} +7 -10
- package/build/cjs/searchParams.js.map +1 -0
- package/build/cjs/{packages/router-core/src/utils.js → utils.js} +10 -24
- package/build/cjs/utils.js.map +1 -0
- package/build/esm/index.js +156 -1116
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +59 -49
- package/build/stats-react.json +160 -154
- package/build/types/index.d.ts +53 -40
- package/build/umd/index.development.js +151 -294
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/link.ts +2 -2
- package/src/path.ts +2 -2
- package/src/route.ts +8 -5
- package/src/routeConfig.ts +77 -63
- package/src/routeInfo.ts +11 -6
- package/src/routeMatch.ts +1 -1
- package/src/router.ts +114 -51
- package/src/utils.ts +2 -2
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js +0 -33
- package/build/cjs/node_modules/@babel/runtime/helpers/esm/extends.js.map +0 -1
- package/build/cjs/node_modules/history/index.js +0 -815
- package/build/cjs/node_modules/history/index.js.map +0 -1
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +0 -30
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +0 -1
- package/build/cjs/packages/router-core/src/path.js.map +0 -1
- package/build/cjs/packages/router-core/src/qss.js.map +0 -1
- package/build/cjs/packages/router-core/src/route.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +0 -1
- package/build/cjs/packages/router-core/src/routeMatch.js.map +0 -1
- package/build/cjs/packages/router-core/src/router.js.map +0 -1
- package/build/cjs/packages/router-core/src/searchParams.js.map +0 -1
- package/build/cjs/packages/router-core/src/utils.js.map +0 -1
|
@@ -12,21 +12,25 @@
|
|
|
12
12
|
|
|
13
13
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
14
14
|
|
|
15
|
-
var _rollupPluginBabelHelpers = require('
|
|
16
|
-
var
|
|
17
|
-
var
|
|
15
|
+
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js');
|
|
16
|
+
var history = require('history');
|
|
17
|
+
var invariant = require('tiny-invariant');
|
|
18
18
|
var path = require('./path.js');
|
|
19
19
|
var route = require('./route.js');
|
|
20
20
|
var routeMatch = require('./routeMatch.js');
|
|
21
21
|
var searchParams = require('./searchParams.js');
|
|
22
22
|
var utils = require('./utils.js');
|
|
23
23
|
|
|
24
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
25
|
+
|
|
26
|
+
var invariant__default = /*#__PURE__*/_interopDefaultLegacy(invariant);
|
|
27
|
+
|
|
24
28
|
var _window$document;
|
|
25
29
|
// Detect if we're in the DOM
|
|
26
|
-
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
|
|
27
|
-
|
|
28
|
-
const createDefaultHistory = () => isServer ? index.createMemoryHistory() : index.createBrowserHistory();
|
|
30
|
+
const isServer = typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement);
|
|
29
31
|
|
|
32
|
+
// This is the default history object if none is defined
|
|
33
|
+
const createDefaultHistory = () => isServer ? history.createMemoryHistory() : history.createBrowserHistory();
|
|
30
34
|
function getInitialRouterState() {
|
|
31
35
|
return {
|
|
32
36
|
status: 'idle',
|
|
@@ -39,22 +43,19 @@ function getInitialRouterState() {
|
|
|
39
43
|
isPreloading: false
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
|
-
|
|
43
46
|
function createRouter(userOptions) {
|
|
44
47
|
var _userOptions$stringif, _userOptions$parseSea;
|
|
45
|
-
|
|
46
48
|
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
47
|
-
|
|
48
49
|
const originalOptions = _rollupPluginBabelHelpers["extends"]({
|
|
49
50
|
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
50
51
|
defaultLoaderMaxAge: 0,
|
|
51
52
|
defaultPreloadMaxAge: 2000,
|
|
52
|
-
defaultPreloadDelay: 50
|
|
53
|
+
defaultPreloadDelay: 50,
|
|
54
|
+
context: undefined
|
|
53
55
|
}, userOptions, {
|
|
54
56
|
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : searchParams.defaultStringifySearch,
|
|
55
57
|
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : searchParams.defaultParseSearch
|
|
56
58
|
});
|
|
57
|
-
|
|
58
59
|
let router = {
|
|
59
60
|
types: undefined,
|
|
60
61
|
// public api
|
|
@@ -62,13 +63,11 @@ function createRouter(userOptions) {
|
|
|
62
63
|
options: originalOptions,
|
|
63
64
|
listeners: [],
|
|
64
65
|
// Resolved after construction
|
|
65
|
-
context: {},
|
|
66
66
|
basepath: '',
|
|
67
67
|
routeTree: undefined,
|
|
68
68
|
routesById: {},
|
|
69
69
|
location: undefined,
|
|
70
70
|
//
|
|
71
|
-
navigationPromise: Promise.resolve(),
|
|
72
71
|
resolveNavigation: () => {},
|
|
73
72
|
matchCache: {},
|
|
74
73
|
state: getInitialRouterState(),
|
|
@@ -89,30 +88,38 @@ function createRouter(userOptions) {
|
|
|
89
88
|
notify: () => {
|
|
90
89
|
const isFetching = router.state.status === 'loading' || router.state.matches.some(d => d.isFetching);
|
|
91
90
|
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId));
|
|
92
|
-
|
|
93
91
|
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
94
92
|
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
95
93
|
isFetching,
|
|
96
94
|
isPreloading
|
|
97
95
|
});
|
|
98
96
|
}
|
|
99
|
-
|
|
100
97
|
cascadeLoaderData(router.state.matches);
|
|
101
98
|
router.listeners.forEach(listener => listener(router));
|
|
102
99
|
},
|
|
103
|
-
|
|
104
|
-
return
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
dehydrate: () => {
|
|
101
|
+
return {
|
|
102
|
+
location: router.location,
|
|
103
|
+
state: _rollupPluginBabelHelpers["extends"]({}, utils.pick(router.state, ['status', 'location', 'lastUpdated', 'location']), {
|
|
104
|
+
matches: router.state.matches.map(match => utils.pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
105
|
+
}),
|
|
106
|
+
context: router.options.context
|
|
107
|
+
};
|
|
107
108
|
},
|
|
108
|
-
|
|
109
|
+
hydrate: dehydratedState => {
|
|
110
|
+
// Update the location
|
|
111
|
+
router.location = dehydratedState.location;
|
|
112
|
+
|
|
113
|
+
// Update the context
|
|
114
|
+
router.options.context = dehydratedState.context;
|
|
115
|
+
|
|
109
116
|
// Match the routes
|
|
110
117
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
111
118
|
strictParseParams: true
|
|
112
119
|
});
|
|
113
120
|
matches.forEach((match, index) => {
|
|
114
|
-
const dehydratedMatch = dehydratedState.matches[index];
|
|
115
|
-
|
|
121
|
+
const dehydratedMatch = dehydratedState.state.matches[index];
|
|
122
|
+
invariant__default["default"](dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
116
123
|
Object.assign(match, dehydratedMatch);
|
|
117
124
|
});
|
|
118
125
|
matches.forEach(match => match.__.validate());
|
|
@@ -125,32 +132,29 @@ function createRouter(userOptions) {
|
|
|
125
132
|
to: '.',
|
|
126
133
|
search: true,
|
|
127
134
|
hash: true
|
|
128
|
-
});
|
|
129
|
-
// to the current location. Otherwise, load the current location.
|
|
130
|
-
|
|
135
|
+
});
|
|
131
136
|
|
|
137
|
+
// If the current location isn't updated, trigger a navigation
|
|
138
|
+
// to the current location. Otherwise, load the current location.
|
|
132
139
|
if (next.href !== router.location.href) {
|
|
133
140
|
router.__.commitLocation(next, true);
|
|
134
141
|
}
|
|
135
|
-
|
|
136
142
|
if (!router.state.matches.length) {
|
|
137
143
|
router.load();
|
|
138
144
|
}
|
|
139
|
-
|
|
140
145
|
const unsub = router.history.listen(event => {
|
|
141
146
|
router.load(router.__.parseLocation(event.location, router.location));
|
|
142
|
-
});
|
|
143
|
-
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
147
|
+
});
|
|
144
148
|
|
|
149
|
+
// addEventListener does not exist in React Native, but window does
|
|
150
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
145
151
|
if (!isServer && window.addEventListener) {
|
|
146
152
|
// Listen to visibillitychange and focus
|
|
147
153
|
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
148
154
|
window.addEventListener('focus', router.onFocus, false);
|
|
149
155
|
}
|
|
150
|
-
|
|
151
156
|
return () => {
|
|
152
157
|
unsub();
|
|
153
|
-
|
|
154
158
|
if (!isServer && window.removeEventListener) {
|
|
155
159
|
// Be sure to unsubscribe if a new handler is set
|
|
156
160
|
window.removeEventListener('visibilitychange', router.onFocus);
|
|
@@ -163,28 +167,23 @@ function createRouter(userOptions) {
|
|
|
163
167
|
},
|
|
164
168
|
update: opts => {
|
|
165
169
|
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
166
|
-
|
|
167
170
|
if (!router.location || newHistory) {
|
|
168
171
|
if (opts != null && opts.history) {
|
|
169
172
|
router.history = opts.history;
|
|
170
173
|
}
|
|
171
|
-
|
|
172
174
|
router.location = router.__.parseLocation(router.history.location);
|
|
173
175
|
router.state.location = router.location;
|
|
174
176
|
}
|
|
175
|
-
|
|
176
177
|
Object.assign(router.options, opts);
|
|
177
178
|
const {
|
|
178
179
|
basepath,
|
|
179
180
|
routeConfig
|
|
180
181
|
} = router.options;
|
|
181
182
|
router.basepath = path.cleanPath("/" + (basepath != null ? basepath : ''));
|
|
182
|
-
|
|
183
183
|
if (routeConfig) {
|
|
184
184
|
router.routesById = {};
|
|
185
185
|
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
186
186
|
}
|
|
187
|
-
|
|
188
187
|
return router;
|
|
189
188
|
},
|
|
190
189
|
cancelMatches: () => {
|
|
@@ -196,31 +195,18 @@ function createRouter(userOptions) {
|
|
|
196
195
|
load: async next => {
|
|
197
196
|
const id = Math.random();
|
|
198
197
|
router.startedLoadingAt = id;
|
|
199
|
-
|
|
200
198
|
if (next) {
|
|
201
199
|
// Ingest the new location
|
|
202
200
|
router.location = next;
|
|
203
|
-
}
|
|
204
|
-
|
|
201
|
+
}
|
|
205
202
|
|
|
206
|
-
|
|
203
|
+
// Cancel any pending matches
|
|
204
|
+
router.cancelMatches();
|
|
207
205
|
|
|
206
|
+
// Match the routes
|
|
208
207
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
209
208
|
strictParseParams: true
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
try {
|
|
213
|
-
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
214
|
-
context: router.context
|
|
215
|
-
})));
|
|
216
|
-
} catch (err) {
|
|
217
|
-
if (err != null && err.then) {
|
|
218
|
-
await new Promise(() => {});
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
throw err;
|
|
222
|
-
}
|
|
223
|
-
|
|
209
|
+
});
|
|
224
210
|
if (typeof document !== 'undefined') {
|
|
225
211
|
router.state = _rollupPluginBabelHelpers["extends"]({}, router.state, {
|
|
226
212
|
pending: {
|
|
@@ -237,18 +223,29 @@ function createRouter(userOptions) {
|
|
|
237
223
|
});
|
|
238
224
|
}
|
|
239
225
|
|
|
240
|
-
|
|
226
|
+
// Check if each match middleware to see if the route can be accessed
|
|
227
|
+
try {
|
|
228
|
+
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
229
|
+
router: router,
|
|
230
|
+
match
|
|
231
|
+
})));
|
|
232
|
+
} catch (err) {
|
|
233
|
+
if (err != null && err.then) {
|
|
234
|
+
await new Promise(() => {});
|
|
235
|
+
}
|
|
236
|
+
throw err;
|
|
237
|
+
}
|
|
238
|
+
router.notify();
|
|
241
239
|
|
|
240
|
+
// Load the matches
|
|
242
241
|
await router.loadMatches(matches);
|
|
243
|
-
|
|
244
242
|
if (router.startedLoadingAt !== id) {
|
|
245
243
|
// Ignore side-effects of match loading
|
|
246
244
|
return router.navigationPromise;
|
|
247
245
|
}
|
|
248
|
-
|
|
249
246
|
const previousMatches = router.state.matches;
|
|
250
247
|
const exiting = [],
|
|
251
|
-
|
|
248
|
+
staying = [];
|
|
252
249
|
previousMatches.forEach(d => {
|
|
253
250
|
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
254
251
|
staying.push(d);
|
|
@@ -262,19 +259,17 @@ function createRouter(userOptions) {
|
|
|
262
259
|
const now = Date.now();
|
|
263
260
|
exiting.forEach(d => {
|
|
264
261
|
var _ref, _d$options$loaderGcMa, _ref2, _d$options$loaderMaxA;
|
|
265
|
-
|
|
266
262
|
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
267
263
|
params: d.params,
|
|
268
264
|
search: d.routeSearch
|
|
269
|
-
});
|
|
265
|
+
});
|
|
270
266
|
|
|
267
|
+
// Clear idle error states when match leaves
|
|
271
268
|
if (d.status === 'error' && !d.isFetching) {
|
|
272
269
|
d.status = 'idle';
|
|
273
270
|
d.error = undefined;
|
|
274
271
|
}
|
|
275
|
-
|
|
276
272
|
const gc = Math.max((_ref = (_d$options$loaderGcMa = d.options.loaderGcMaxAge) != null ? _d$options$loaderGcMa : router.options.defaultLoaderGcMaxAge) != null ? _ref : 0, (_ref2 = (_d$options$loaderMaxA = d.options.loaderMaxAge) != null ? _d$options$loaderMaxA : router.options.defaultLoaderMaxAge) != null ? _ref2 : 0);
|
|
277
|
-
|
|
278
273
|
if (gc > 0) {
|
|
279
274
|
router.matchCache[d.matchId] = {
|
|
280
275
|
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
@@ -295,12 +290,10 @@ function createRouter(userOptions) {
|
|
|
295
290
|
});
|
|
296
291
|
delete router.matchCache[d.matchId];
|
|
297
292
|
});
|
|
298
|
-
|
|
299
293
|
if (router.startedLoadingAt !== id) {
|
|
300
294
|
// Ignore side-effects of match loading
|
|
301
295
|
return;
|
|
302
296
|
}
|
|
303
|
-
|
|
304
297
|
matches.forEach(match => {
|
|
305
298
|
// Clear actions
|
|
306
299
|
if (match.action) {
|
|
@@ -320,18 +313,19 @@ function createRouter(userOptions) {
|
|
|
320
313
|
cleanMatchCache: () => {
|
|
321
314
|
const now = Date.now();
|
|
322
315
|
Object.keys(router.matchCache).forEach(matchId => {
|
|
323
|
-
const entry = router.matchCache[matchId];
|
|
316
|
+
const entry = router.matchCache[matchId];
|
|
324
317
|
|
|
318
|
+
// Don't remove loading matches
|
|
325
319
|
if (entry.match.status === 'loading') {
|
|
326
320
|
return;
|
|
327
|
-
}
|
|
328
|
-
|
|
321
|
+
}
|
|
329
322
|
|
|
323
|
+
// Do not remove successful matches that are still valid
|
|
330
324
|
if (entry.gc > 0 && entry.gc > now) {
|
|
331
325
|
return;
|
|
332
|
-
}
|
|
333
|
-
|
|
326
|
+
}
|
|
334
327
|
|
|
328
|
+
// Everything else gets removed
|
|
335
329
|
delete router.matchCache[matchId];
|
|
336
330
|
});
|
|
337
331
|
},
|
|
@@ -339,7 +333,6 @@ function createRouter(userOptions) {
|
|
|
339
333
|
if (navigateOpts === void 0) {
|
|
340
334
|
navigateOpts = router.location;
|
|
341
335
|
}
|
|
342
|
-
|
|
343
336
|
const next = router.buildNext(navigateOpts);
|
|
344
337
|
const matches = router.matchRoutes(next.pathname, {
|
|
345
338
|
strictParseParams: true
|
|
@@ -349,11 +342,9 @@ function createRouter(userOptions) {
|
|
|
349
342
|
},
|
|
350
343
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
351
344
|
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
352
|
-
|
|
353
345
|
if (navigateOpts === void 0) {
|
|
354
346
|
navigateOpts = router.location;
|
|
355
347
|
}
|
|
356
|
-
|
|
357
348
|
const next = router.buildNext(navigateOpts);
|
|
358
349
|
const matches = router.matchRoutes(next.pathname, {
|
|
359
350
|
strictParseParams: true
|
|
@@ -367,90 +358,70 @@ function createRouter(userOptions) {
|
|
|
367
358
|
},
|
|
368
359
|
matchRoutes: (pathname, opts) => {
|
|
369
360
|
var _router$state$pending3, _router$state$pending4;
|
|
370
|
-
|
|
371
361
|
router.cleanMatchCache();
|
|
372
362
|
const matches = [];
|
|
373
|
-
|
|
374
363
|
if (!router.routeTree) {
|
|
375
364
|
return matches;
|
|
376
365
|
}
|
|
377
|
-
|
|
378
366
|
const existingMatches = [...router.state.matches, ...((_router$state$pending3 = (_router$state$pending4 = router.state.pending) == null ? void 0 : _router$state$pending4.matches) != null ? _router$state$pending3 : [])];
|
|
379
|
-
|
|
380
367
|
const recurse = async routes => {
|
|
381
368
|
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
382
|
-
|
|
383
369
|
const parentMatch = utils.last(matches);
|
|
384
370
|
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
385
371
|
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
386
372
|
let foundRoutes = [];
|
|
387
|
-
|
|
388
373
|
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
389
374
|
routes.some(route => {
|
|
390
375
|
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
391
|
-
|
|
392
376
|
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
393
377
|
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
394
378
|
}
|
|
395
|
-
|
|
396
379
|
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
397
380
|
const matchParams = path.matchPathname(pathname, {
|
|
398
381
|
to: route.fullPath,
|
|
399
382
|
fuzzy,
|
|
400
383
|
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
401
384
|
});
|
|
402
|
-
|
|
403
385
|
if (matchParams) {
|
|
404
386
|
let parsedParams;
|
|
405
|
-
|
|
406
387
|
try {
|
|
407
388
|
var _route$options$parseP;
|
|
408
|
-
|
|
409
389
|
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
410
390
|
} catch (err) {
|
|
411
391
|
if (opts != null && opts.strictParseParams) {
|
|
412
392
|
throw err;
|
|
413
393
|
}
|
|
414
394
|
}
|
|
415
|
-
|
|
416
395
|
params = _rollupPluginBabelHelpers["extends"]({}, params, parsedParams);
|
|
417
396
|
}
|
|
418
|
-
|
|
419
397
|
if (!!matchParams) {
|
|
420
398
|
foundRoutes = [...parentRoutes, route];
|
|
421
399
|
}
|
|
422
|
-
|
|
423
400
|
return !!foundRoutes.length;
|
|
424
401
|
});
|
|
425
402
|
return !!foundRoutes.length;
|
|
426
403
|
};
|
|
427
|
-
|
|
428
404
|
findMatchInRoutes([], filteredRoutes);
|
|
429
|
-
|
|
430
405
|
if (!foundRoutes.length) {
|
|
431
406
|
return;
|
|
432
407
|
}
|
|
433
|
-
|
|
434
408
|
foundRoutes.forEach(foundRoute => {
|
|
435
409
|
var _router$matchCache$ma;
|
|
436
|
-
|
|
437
410
|
const interpolatedPath = path.interpolatePath(foundRoute.routePath, params);
|
|
438
411
|
const matchId = path.interpolatePath(foundRoute.routeId, params, true);
|
|
439
412
|
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || routeMatch.createRouteMatch(router, foundRoute, {
|
|
440
413
|
parentMatch,
|
|
441
414
|
matchId,
|
|
442
415
|
params,
|
|
443
|
-
pathname: path.joinPaths([
|
|
416
|
+
pathname: path.joinPaths([router.basepath, interpolatedPath])
|
|
444
417
|
});
|
|
445
418
|
matches.push(match);
|
|
446
419
|
});
|
|
447
420
|
const foundRoute = utils.last(foundRoutes);
|
|
448
|
-
|
|
449
421
|
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
450
422
|
recurse(foundRoute.childRoutes);
|
|
451
423
|
}
|
|
452
424
|
};
|
|
453
|
-
|
|
454
425
|
recurse([router.routeTree]);
|
|
455
426
|
cascadeLoaderData(matches);
|
|
456
427
|
return matches;
|
|
@@ -459,14 +430,11 @@ function createRouter(userOptions) {
|
|
|
459
430
|
const matchPromises = resolvedMatches.map(async match => {
|
|
460
431
|
// Validate the match (loads search params etc)
|
|
461
432
|
match.__.validate();
|
|
462
|
-
|
|
463
433
|
match.load(loaderOpts);
|
|
464
434
|
const search = match.search;
|
|
465
|
-
|
|
466
435
|
if (search.__data && search.__data.matchId !== match.matchId) {
|
|
467
436
|
return;
|
|
468
437
|
}
|
|
469
|
-
|
|
470
438
|
if (match.__.loadPromise) {
|
|
471
439
|
// Wait for the first sign of activity from the match
|
|
472
440
|
await match.__.loadPromise;
|
|
@@ -478,7 +446,6 @@ function createRouter(userOptions) {
|
|
|
478
446
|
loadMatchData: async routeMatch => {
|
|
479
447
|
if (isServer || !router.options.useServerData) {
|
|
480
448
|
var _await$routeMatch$opt;
|
|
481
|
-
|
|
482
449
|
return (_await$routeMatch$opt = await (routeMatch.options.loader == null ? void 0 : routeMatch.options.loader({
|
|
483
450
|
// parentLoaderPromise: routeMatch.parentMatch?.__.dataPromise,
|
|
484
451
|
params: routeMatch.params,
|
|
@@ -494,21 +461,30 @@ function createRouter(userOptions) {
|
|
|
494
461
|
}
|
|
495
462
|
})
|
|
496
463
|
});
|
|
497
|
-
const res = await fetch(next.href, {
|
|
498
|
-
method: 'GET' // signal: routeMatch.__.abortController.signal,
|
|
499
464
|
|
|
465
|
+
// Refresh:
|
|
466
|
+
// '/dashboard'
|
|
467
|
+
// '/dashboard/invoices/'
|
|
468
|
+
// '/dashboard/invoices/123'
|
|
469
|
+
|
|
470
|
+
// New:
|
|
471
|
+
// '/dashboard/invoices/456'
|
|
472
|
+
|
|
473
|
+
// TODO: batch requests when possible
|
|
474
|
+
|
|
475
|
+
const res = await fetch(next.href, {
|
|
476
|
+
method: 'GET'
|
|
477
|
+
// signal: routeMatch.__.abortController.signal,
|
|
500
478
|
});
|
|
501
479
|
|
|
502
480
|
if (res.ok) {
|
|
503
481
|
return res.json();
|
|
504
482
|
}
|
|
505
|
-
|
|
506
483
|
throw new Error('Failed to fetch match data');
|
|
507
484
|
}
|
|
508
485
|
},
|
|
509
486
|
invalidateRoute: opts => {
|
|
510
487
|
var _router$state$pending5, _router$state$pending6;
|
|
511
|
-
|
|
512
488
|
const next = router.buildNext(opts);
|
|
513
489
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
514
490
|
[...router.state.matches, ...((_router$state$pending5 = (_router$state$pending6 = router.state.pending) == null ? void 0 : _router$state$pending6.matches) != null ? _router$state$pending5 : [])].forEach(match => {
|
|
@@ -527,25 +503,21 @@ function createRouter(userOptions) {
|
|
|
527
503
|
},
|
|
528
504
|
matchRoute: (location, opts) => {
|
|
529
505
|
var _location$from;
|
|
530
|
-
|
|
531
506
|
// const location = router.buildNext(opts)
|
|
507
|
+
|
|
532
508
|
location = _rollupPluginBabelHelpers["extends"]({}, location, {
|
|
533
509
|
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
534
510
|
});
|
|
535
511
|
const next = router.buildNext(location);
|
|
536
|
-
|
|
537
512
|
if (opts != null && opts.pending) {
|
|
538
513
|
var _router$state$pending7;
|
|
539
|
-
|
|
540
514
|
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
541
515
|
return false;
|
|
542
516
|
}
|
|
543
|
-
|
|
544
517
|
return !!path.matchPathname(router.state.pending.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
545
518
|
to: next.pathname
|
|
546
519
|
}));
|
|
547
520
|
}
|
|
548
|
-
|
|
549
521
|
return !!path.matchPathname(router.state.location.pathname, _rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
550
522
|
to: next.pathname
|
|
551
523
|
}));
|
|
@@ -561,18 +533,17 @@ function createRouter(userOptions) {
|
|
|
561
533
|
} = _ref7;
|
|
562
534
|
// If this link simply reloads the current route,
|
|
563
535
|
// make sure it has a new key so it will trigger a data refresh
|
|
536
|
+
|
|
564
537
|
// If this `to` is a valid external URL, return
|
|
565
538
|
// null for LinkUtils
|
|
566
539
|
const toString = String(to);
|
|
567
540
|
const fromString = String(from);
|
|
568
541
|
let isExternal;
|
|
569
|
-
|
|
570
542
|
try {
|
|
571
543
|
new URL("" + toString);
|
|
572
544
|
isExternal = true;
|
|
573
545
|
} catch (e) {}
|
|
574
|
-
|
|
575
|
-
tinyInvariant["default"](!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
546
|
+
invariant__default["default"](!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
576
547
|
return router.__.navigate({
|
|
577
548
|
from: fromString,
|
|
578
549
|
to: toString,
|
|
@@ -584,7 +555,6 @@ function createRouter(userOptions) {
|
|
|
584
555
|
},
|
|
585
556
|
buildLink: _ref8 => {
|
|
586
557
|
var _preload, _ref9;
|
|
587
|
-
|
|
588
558
|
let {
|
|
589
559
|
from,
|
|
590
560
|
to = '.',
|
|
@@ -600,11 +570,12 @@ function createRouter(userOptions) {
|
|
|
600
570
|
preloadDelay: userPreloadDelay,
|
|
601
571
|
disabled
|
|
602
572
|
} = _ref8;
|
|
603
|
-
|
|
604
573
|
// If this link simply reloads the current route,
|
|
605
574
|
// make sure it has a new key so it will trigger a data refresh
|
|
575
|
+
|
|
606
576
|
// If this `to` is a valid external URL, return
|
|
607
577
|
// null for LinkUtils
|
|
578
|
+
|
|
608
579
|
try {
|
|
609
580
|
new URL("" + to);
|
|
610
581
|
return {
|
|
@@ -612,7 +583,6 @@ function createRouter(userOptions) {
|
|
|
612
583
|
href: to
|
|
613
584
|
};
|
|
614
585
|
} catch (e) {}
|
|
615
|
-
|
|
616
586
|
const nextOpts = {
|
|
617
587
|
from,
|
|
618
588
|
to,
|
|
@@ -623,33 +593,35 @@ function createRouter(userOptions) {
|
|
|
623
593
|
};
|
|
624
594
|
const next = router.buildNext(nextOpts);
|
|
625
595
|
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
626
|
-
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
596
|
+
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
627
597
|
|
|
598
|
+
// Compare path/hash for matches
|
|
628
599
|
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
629
600
|
const currentPathSplit = router.state.location.pathname.split('/');
|
|
630
601
|
const nextPathSplit = next.pathname.split('/');
|
|
631
602
|
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
632
|
-
const hashIsEqual = router.state.location.hash === next.hash;
|
|
633
|
-
|
|
603
|
+
const hashIsEqual = router.state.location.hash === next.hash;
|
|
604
|
+
// Combine the matches based on user options
|
|
634
605
|
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
635
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
606
|
+
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
636
607
|
|
|
637
|
-
|
|
608
|
+
// The final "active" test
|
|
609
|
+
const isActive = pathTest && hashTest;
|
|
638
610
|
|
|
611
|
+
// The click handler
|
|
639
612
|
const handleClick = e => {
|
|
640
613
|
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
641
614
|
e.preventDefault();
|
|
642
|
-
|
|
643
615
|
if (pathIsEqual && !search && !hash) {
|
|
644
616
|
router.invalidateRoute(nextOpts);
|
|
645
|
-
}
|
|
646
|
-
|
|
617
|
+
}
|
|
647
618
|
|
|
619
|
+
// All is well? Navigate!)
|
|
648
620
|
router.__.navigate(nextOpts);
|
|
649
621
|
}
|
|
650
|
-
};
|
|
651
|
-
|
|
622
|
+
};
|
|
652
623
|
|
|
624
|
+
// The click handler
|
|
653
625
|
const handleFocus = e => {
|
|
654
626
|
if (preload) {
|
|
655
627
|
router.preloadRoute(nextOpts, {
|
|
@@ -658,15 +630,12 @@ function createRouter(userOptions) {
|
|
|
658
630
|
});
|
|
659
631
|
}
|
|
660
632
|
};
|
|
661
|
-
|
|
662
633
|
const handleEnter = e => {
|
|
663
634
|
const target = e.target || {};
|
|
664
|
-
|
|
665
635
|
if (preload) {
|
|
666
636
|
if (target.preloadTimeout) {
|
|
667
637
|
return;
|
|
668
638
|
}
|
|
669
|
-
|
|
670
639
|
target.preloadTimeout = setTimeout(() => {
|
|
671
640
|
target.preloadTimeout = null;
|
|
672
641
|
router.preloadRoute(nextOpts, {
|
|
@@ -676,16 +645,13 @@ function createRouter(userOptions) {
|
|
|
676
645
|
}, preloadDelay);
|
|
677
646
|
}
|
|
678
647
|
};
|
|
679
|
-
|
|
680
648
|
const handleLeave = e => {
|
|
681
649
|
const target = e.target || {};
|
|
682
|
-
|
|
683
650
|
if (target.preloadTimeout) {
|
|
684
651
|
clearTimeout(target.preloadTimeout);
|
|
685
652
|
target.preloadTimeout = null;
|
|
686
653
|
}
|
|
687
654
|
};
|
|
688
|
-
|
|
689
655
|
return {
|
|
690
656
|
type: 'internal',
|
|
691
657
|
next,
|
|
@@ -699,21 +665,15 @@ function createRouter(userOptions) {
|
|
|
699
665
|
},
|
|
700
666
|
buildNext: opts => {
|
|
701
667
|
const next = router.__.buildLocation(opts);
|
|
702
|
-
|
|
703
668
|
const matches = router.matchRoutes(next.pathname);
|
|
704
|
-
|
|
705
669
|
const __preSearchFilters = matches.map(match => {
|
|
706
670
|
var _match$options$preSea;
|
|
707
|
-
|
|
708
671
|
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
709
672
|
}).flat().filter(Boolean);
|
|
710
|
-
|
|
711
673
|
const __postSearchFilters = matches.map(match => {
|
|
712
674
|
var _match$options$postSe;
|
|
713
|
-
|
|
714
675
|
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
715
676
|
}).flat().filter(Boolean);
|
|
716
|
-
|
|
717
677
|
return router.__.buildLocation(_rollupPluginBabelHelpers["extends"]({}, opts, {
|
|
718
678
|
__preSearchFilters,
|
|
719
679
|
__postSearchFilters
|
|
@@ -726,12 +686,10 @@ function createRouter(userOptions) {
|
|
|
726
686
|
const routeOptions = routeConfig.options;
|
|
727
687
|
const route$1 = route.createRoute(routeConfig, routeOptions, parent, router);
|
|
728
688
|
const existingRoute = router.routesById[route$1.routeId];
|
|
729
|
-
|
|
730
689
|
if (existingRoute) {
|
|
731
690
|
if (process.env.NODE_ENV !== 'production') {
|
|
732
691
|
console.warn("Duplicate routes found with id: " + String(route$1.routeId), router.routesById, route$1);
|
|
733
692
|
}
|
|
734
|
-
|
|
735
693
|
throw new Error();
|
|
736
694
|
}
|
|
737
695
|
router.routesById[route$1.routeId] = route$1;
|
|
@@ -740,13 +698,11 @@ function createRouter(userOptions) {
|
|
|
740
698
|
return route$1;
|
|
741
699
|
});
|
|
742
700
|
};
|
|
743
|
-
|
|
744
701
|
const routes = recurseRoutes([rootRouteConfig]);
|
|
745
702
|
return routes[0];
|
|
746
703
|
},
|
|
747
704
|
parseLocation: (location, previousLocation) => {
|
|
748
705
|
var _location$hash$split$;
|
|
749
|
-
|
|
750
706
|
const parsedSearch = router.options.parseSearch(location.search);
|
|
751
707
|
return {
|
|
752
708
|
pathname: location.pathname,
|
|
@@ -764,41 +720,36 @@ function createRouter(userOptions) {
|
|
|
764
720
|
},
|
|
765
721
|
buildLocation: function buildLocation(dest) {
|
|
766
722
|
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
767
|
-
|
|
768
723
|
if (dest === void 0) {
|
|
769
724
|
dest = {};
|
|
770
725
|
}
|
|
771
|
-
|
|
772
726
|
// const resolvedFrom: Location = {
|
|
773
727
|
// ...router.location,
|
|
774
728
|
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
775
|
-
|
|
776
729
|
let pathname = path.resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
777
|
-
|
|
778
730
|
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
779
731
|
strictParseParams: true
|
|
780
732
|
});
|
|
781
733
|
const toMatches = router.matchRoutes(pathname);
|
|
782
|
-
|
|
783
734
|
const prevParams = _rollupPluginBabelHelpers["extends"]({}, (_last = utils.last(fromMatches)) == null ? void 0 : _last.params);
|
|
784
|
-
|
|
785
735
|
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : utils.functionalUpdate(dest.params, prevParams);
|
|
786
|
-
|
|
787
736
|
if (nextParams) {
|
|
788
737
|
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
789
738
|
Object.assign({}, nextParams, fn(nextParams));
|
|
790
739
|
});
|
|
791
740
|
}
|
|
741
|
+
pathname = path.interpolatePath(pathname, nextParams != null ? nextParams : {});
|
|
792
742
|
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search; // Then the link/navigate function
|
|
743
|
+
// Pre filters first
|
|
744
|
+
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.location.search) : router.location.search;
|
|
796
745
|
|
|
746
|
+
// Then the link/navigate function
|
|
797
747
|
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
798
748
|
: dest.search ? (_functionalUpdate = utils.functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
799
749
|
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
800
|
-
: {};
|
|
750
|
+
: {};
|
|
801
751
|
|
|
752
|
+
// Then post filters
|
|
802
753
|
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
803
754
|
const search = utils.replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
804
755
|
const searchStr = router.options.stringifySearch(search);
|
|
@@ -818,17 +769,13 @@ function createRouter(userOptions) {
|
|
|
818
769
|
const id = '' + Date.now() + Math.random();
|
|
819
770
|
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
820
771
|
let nextAction = 'replace';
|
|
821
|
-
|
|
822
772
|
if (!replace) {
|
|
823
773
|
nextAction = 'push';
|
|
824
774
|
}
|
|
825
|
-
|
|
826
775
|
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
827
|
-
|
|
828
776
|
if (isSameUrl && !next.key) {
|
|
829
777
|
nextAction = 'replace';
|
|
830
778
|
}
|
|
831
|
-
|
|
832
779
|
if (nextAction === 'replace') {
|
|
833
780
|
history.replace({
|
|
834
781
|
pathname: next.pathname,
|
|
@@ -846,33 +793,30 @@ function createRouter(userOptions) {
|
|
|
846
793
|
id
|
|
847
794
|
});
|
|
848
795
|
}
|
|
849
|
-
|
|
850
796
|
router.navigationPromise = new Promise(resolve => {
|
|
851
797
|
const previousNavigationResolve = router.resolveNavigation;
|
|
852
|
-
|
|
853
798
|
router.resolveNavigation = () => {
|
|
854
799
|
previousNavigationResolve();
|
|
855
800
|
resolve();
|
|
801
|
+
delete router.navigationPromise;
|
|
856
802
|
};
|
|
857
803
|
});
|
|
858
804
|
return router.navigationPromise;
|
|
859
805
|
}
|
|
860
806
|
}
|
|
861
807
|
};
|
|
862
|
-
router.update(userOptions);
|
|
808
|
+
router.update(userOptions);
|
|
863
809
|
|
|
810
|
+
// Allow frameworks to hook into the router creation
|
|
864
811
|
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
865
812
|
return router;
|
|
866
813
|
}
|
|
867
|
-
|
|
868
814
|
function isCtrlEvent(e) {
|
|
869
815
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
870
816
|
}
|
|
871
|
-
|
|
872
817
|
function cascadeLoaderData(matches) {
|
|
873
818
|
matches.forEach((match, index) => {
|
|
874
819
|
const parent = matches[index - 1];
|
|
875
|
-
|
|
876
820
|
if (parent) {
|
|
877
821
|
match.loaderData = utils.replaceEqualDeep(match.loaderData, _rollupPluginBabelHelpers["extends"]({}, parent.loaderData, match.routeLoaderData));
|
|
878
822
|
}
|