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