@tanstack/router-core 0.0.1-alpha.1 → 0.0.1-alpha.10
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/node_modules/tiny-invariant/dist/esm/tiny-invariant.js +30 -0
- package/build/cjs/node_modules/tiny-invariant/dist/esm/tiny-invariant.js.map +1 -0
- package/build/cjs/packages/router-core/src/index.js +35 -1421
- package/build/cjs/packages/router-core/src/index.js.map +1 -1
- package/build/cjs/packages/router-core/src/path.js +222 -0
- package/build/cjs/packages/router-core/src/path.js.map +1 -0
- package/build/cjs/packages/router-core/src/qss.js +1 -1
- package/build/cjs/packages/router-core/src/qss.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +126 -0
- package/build/cjs/packages/router-core/src/route.js.map +1 -0
- package/build/cjs/packages/router-core/src/routeConfig.js +69 -0
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -0
- package/build/cjs/packages/router-core/src/routeMatch.js +247 -0
- package/build/cjs/packages/router-core/src/routeMatch.js.map +1 -0
- package/build/cjs/packages/router-core/src/router.js +809 -0
- package/build/cjs/packages/router-core/src/router.js.map +1 -0
- package/build/cjs/packages/router-core/src/searchParams.js +70 -0
- package/build/cjs/packages/router-core/src/searchParams.js.map +1 -0
- package/build/cjs/packages/router-core/src/utils.js +118 -0
- package/build/cjs/packages/router-core/src/utils.js.map +1 -0
- package/build/esm/index.js +1350 -1231
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +388 -46
- package/build/types/index.d.ts +401 -343
- package/build/umd/index.development.js +1218 -1091
- 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/frameworks.ts +13 -0
- package/src/index.ts +15 -2969
- package/src/link.ts +291 -0
- package/src/path.ts +236 -0
- package/src/qss.ts +1 -1
- package/src/route.ts +181 -0
- package/src/routeConfig.ts +523 -0
- package/src/routeInfo.ts +228 -0
- package/src/routeMatch.ts +340 -0
- package/src/router.ts +1211 -0
- package/src/searchParams.ts +54 -0
- package/src/utils.ts +157 -0
- package/src/createRoutes.test.ts +0 -328
|
@@ -31,23 +31,6 @@
|
|
|
31
31
|
return _extends$1.apply(this, arguments);
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
function _extends() {
|
|
35
|
-
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
36
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
37
|
-
var source = arguments[i];
|
|
38
|
-
|
|
39
|
-
for (var key in source) {
|
|
40
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
41
|
-
target[key] = source[key];
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return target;
|
|
47
|
-
};
|
|
48
|
-
return _extends.apply(this, arguments);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
34
|
/**
|
|
52
35
|
* Actions represent the type of change to a location value.
|
|
53
36
|
*
|
|
@@ -189,7 +172,7 @@
|
|
|
189
172
|
|
|
190
173
|
if (index == null) {
|
|
191
174
|
index = 0;
|
|
192
|
-
globalHistory.replaceState(_extends({}, globalHistory.state, {
|
|
175
|
+
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
193
176
|
idx: index
|
|
194
177
|
}), '');
|
|
195
178
|
}
|
|
@@ -204,7 +187,7 @@
|
|
|
204
187
|
state = null;
|
|
205
188
|
}
|
|
206
189
|
|
|
207
|
-
return readOnly(_extends({
|
|
190
|
+
return readOnly(_extends$1({
|
|
208
191
|
pathname: location.pathname,
|
|
209
192
|
hash: '',
|
|
210
193
|
search: ''
|
|
@@ -438,7 +421,7 @@
|
|
|
438
421
|
|
|
439
422
|
if (index == null) {
|
|
440
423
|
index = 0;
|
|
441
|
-
globalHistory.replaceState(_extends({}, globalHistory.state, {
|
|
424
|
+
globalHistory.replaceState(_extends$1({}, globalHistory.state, {
|
|
442
425
|
idx: index
|
|
443
426
|
}), '');
|
|
444
427
|
}
|
|
@@ -465,7 +448,7 @@
|
|
|
465
448
|
state = null;
|
|
466
449
|
}
|
|
467
450
|
|
|
468
|
-
return readOnly(_extends({
|
|
451
|
+
return readOnly(_extends$1({
|
|
469
452
|
pathname: location.pathname,
|
|
470
453
|
hash: '',
|
|
471
454
|
search: ''
|
|
@@ -617,7 +600,7 @@
|
|
|
617
600
|
initialEntries = _options3$initialEntr === void 0 ? ['/'] : _options3$initialEntr,
|
|
618
601
|
initialIndex = _options3.initialIndex;
|
|
619
602
|
var entries = initialEntries.map(function (entry) {
|
|
620
|
-
var location = readOnly(_extends({
|
|
603
|
+
var location = readOnly(_extends$1({
|
|
621
604
|
pathname: '/',
|
|
622
605
|
search: '',
|
|
623
606
|
hash: '',
|
|
@@ -642,7 +625,7 @@
|
|
|
642
625
|
state = null;
|
|
643
626
|
}
|
|
644
627
|
|
|
645
|
-
return readOnly(_extends({
|
|
628
|
+
return readOnly(_extends$1({
|
|
646
629
|
pathname: location.pathname,
|
|
647
630
|
search: '',
|
|
648
631
|
hash: ''
|
|
@@ -839,797 +822,390 @@
|
|
|
839
822
|
return parsedPath;
|
|
840
823
|
}
|
|
841
824
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
i,
|
|
847
|
-
tmp,
|
|
848
|
-
str = '';
|
|
849
|
-
|
|
850
|
-
for (k in obj) {
|
|
851
|
-
if ((tmp = obj[k]) !== void 0) {
|
|
852
|
-
if (Array.isArray(tmp)) {
|
|
853
|
-
for (i = 0; i < tmp.length; i++) {
|
|
854
|
-
str && (str += '&');
|
|
855
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
|
|
856
|
-
}
|
|
857
|
-
} else {
|
|
858
|
-
str && (str += '&');
|
|
859
|
-
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
|
|
860
|
-
}
|
|
825
|
+
var prefix = 'Invariant failed';
|
|
826
|
+
function invariant(condition, message) {
|
|
827
|
+
if (condition) {
|
|
828
|
+
return;
|
|
861
829
|
}
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
830
|
+
var provided = typeof message === 'function' ? message() : message;
|
|
831
|
+
var value = provided ? "".concat(prefix, ": ").concat(provided) : prefix;
|
|
832
|
+
throw new Error(value);
|
|
865
833
|
}
|
|
866
834
|
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
return +str * 0 === 0 ? +str : str;
|
|
873
|
-
}
|
|
835
|
+
// type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
836
|
+
// k: infer I,
|
|
837
|
+
// ) => any
|
|
838
|
+
// ? I
|
|
839
|
+
// : never
|
|
874
840
|
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
841
|
+
/**
|
|
842
|
+
* This function returns `a` if `b` is deeply equal.
|
|
843
|
+
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
844
|
+
* This can be used for structural sharing between JSON values for example.
|
|
845
|
+
*/
|
|
846
|
+
function replaceEqualDeep(prev, next) {
|
|
847
|
+
if (prev === next) {
|
|
848
|
+
return prev;
|
|
849
|
+
}
|
|
880
850
|
|
|
881
|
-
|
|
882
|
-
tmp = tmp.split('=');
|
|
883
|
-
k = tmp.shift();
|
|
851
|
+
const array = Array.isArray(prev) && Array.isArray(next);
|
|
884
852
|
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
}
|
|
890
|
-
|
|
853
|
+
if (array || isPlainObject(prev) && isPlainObject(next)) {
|
|
854
|
+
const aSize = array ? prev.length : Object.keys(prev).length;
|
|
855
|
+
const bItems = array ? next : Object.keys(next);
|
|
856
|
+
const bSize = bItems.length;
|
|
857
|
+
const copy = array ? [] : {};
|
|
858
|
+
let equalItems = 0;
|
|
891
859
|
|
|
892
|
-
|
|
893
|
-
|
|
860
|
+
for (let i = 0; i < bSize; i++) {
|
|
861
|
+
const key = array ? i : bItems[i];
|
|
862
|
+
copy[key] = replaceEqualDeep(prev[key], next[key]);
|
|
894
863
|
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
864
|
+
if (copy[key] === prev[key]) {
|
|
865
|
+
equalItems++;
|
|
866
|
+
}
|
|
867
|
+
}
|
|
899
868
|
|
|
900
|
-
|
|
901
|
-
isRoot = true;
|
|
869
|
+
return aSize === bSize && equalItems === aSize ? prev : copy;
|
|
902
870
|
}
|
|
903
871
|
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
} else {
|
|
907
|
-
warning(!options.path, 'Routes must have a path property.');
|
|
908
|
-
} // Strip the root from parentIds
|
|
872
|
+
return next;
|
|
873
|
+
} // Copied from: https://github.com/jonschlinkert/is-plain-object
|
|
909
874
|
|
|
875
|
+
function isPlainObject(o) {
|
|
876
|
+
if (!hasObjectPrototype(o)) {
|
|
877
|
+
return false;
|
|
878
|
+
} // If has modified constructor
|
|
910
879
|
|
|
911
|
-
if (parentId === rootRouteId) {
|
|
912
|
-
parentId = '';
|
|
913
|
-
}
|
|
914
880
|
|
|
915
|
-
|
|
881
|
+
const ctor = o.constructor;
|
|
916
882
|
|
|
917
|
-
if (
|
|
918
|
-
|
|
919
|
-
}
|
|
883
|
+
if (typeof ctor === 'undefined') {
|
|
884
|
+
return true;
|
|
885
|
+
} // If has modified prototype
|
|
920
886
|
|
|
921
|
-
let id = joinPaths([parentId, path]);
|
|
922
887
|
|
|
923
|
-
|
|
924
|
-
path = '/';
|
|
925
|
-
}
|
|
888
|
+
const prot = ctor.prototype;
|
|
926
889
|
|
|
927
|
-
if (
|
|
928
|
-
|
|
929
|
-
}
|
|
890
|
+
if (!hasObjectPrototype(prot)) {
|
|
891
|
+
return false;
|
|
892
|
+
} // If constructor does not have an Object-specific method
|
|
930
893
|
|
|
931
|
-
const fullPath = id === rootRouteId ? '/' : trimPathRight(id);
|
|
932
|
-
return {
|
|
933
|
-
id: id,
|
|
934
|
-
path: path,
|
|
935
|
-
fullPath: fullPath,
|
|
936
|
-
options: options,
|
|
937
|
-
children,
|
|
938
|
-
addChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id)), false, parentId)
|
|
939
|
-
};
|
|
940
|
-
};
|
|
941
|
-
const rootRouteId = '__root__';
|
|
942
|
-
// Source
|
|
943
|
-
// Detect if we're in the DOM
|
|
944
|
-
const isDOM = Boolean(typeof window !== 'undefined' && window.document && window.document.createElement); // This is the default history object if none is defined
|
|
945
894
|
|
|
946
|
-
|
|
895
|
+
if (!prot.hasOwnProperty('isPrototypeOf')) {
|
|
896
|
+
return false;
|
|
897
|
+
} // Most likely a plain Object
|
|
947
898
|
|
|
948
|
-
function createRouter(userOptions) {
|
|
949
|
-
var _userOptions$stringif, _userOptions$parseSea;
|
|
950
899
|
|
|
951
|
-
|
|
900
|
+
return true;
|
|
901
|
+
}
|
|
952
902
|
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
});
|
|
903
|
+
function hasObjectPrototype(o) {
|
|
904
|
+
return Object.prototype.toString.call(o) === '[object Object]';
|
|
905
|
+
}
|
|
957
906
|
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
routesById: {},
|
|
965
|
-
location: undefined,
|
|
966
|
-
allRouteInfo: undefined,
|
|
967
|
-
//
|
|
968
|
-
navigationPromise: Promise.resolve(),
|
|
969
|
-
resolveNavigation: () => {},
|
|
970
|
-
preloadCache: {},
|
|
971
|
-
state: {
|
|
972
|
-
status: 'idle',
|
|
973
|
-
location: null,
|
|
974
|
-
matches: [],
|
|
975
|
-
actions: {},
|
|
976
|
-
loaderData: {},
|
|
977
|
-
lastUpdated: Date.now()
|
|
978
|
-
},
|
|
979
|
-
startedLoadingAt: Date.now(),
|
|
980
|
-
subscribe: listener => {
|
|
981
|
-
router.listeners.push(listener);
|
|
982
|
-
return () => {
|
|
983
|
-
router.listeners = router.listeners.filter(x => x !== listener);
|
|
984
|
-
};
|
|
985
|
-
},
|
|
986
|
-
getRoute: id => {
|
|
987
|
-
return router.routesById[id];
|
|
988
|
-
},
|
|
989
|
-
notify: () => {
|
|
990
|
-
router.state = _extends$1({}, router.state);
|
|
991
|
-
router.listeners.forEach(listener => listener());
|
|
992
|
-
},
|
|
993
|
-
mount: () => {
|
|
994
|
-
const next = router.buildLocation({
|
|
995
|
-
to: '.',
|
|
996
|
-
search: true,
|
|
997
|
-
hash: true
|
|
998
|
-
}); // If the current location isn't updated, trigger a navigation
|
|
999
|
-
// to the current location. Otherwise, load the current location.
|
|
907
|
+
function last(arr) {
|
|
908
|
+
return arr[arr.length - 1];
|
|
909
|
+
}
|
|
910
|
+
function warning(cond, message) {
|
|
911
|
+
if (cond) {
|
|
912
|
+
if (typeof console !== 'undefined') console.warn(message);
|
|
1000
913
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
}
|
|
1006
|
-
},
|
|
1007
|
-
update: opts => {
|
|
1008
|
-
Object.assign(router.options, opts);
|
|
1009
|
-
const {
|
|
1010
|
-
basepath,
|
|
1011
|
-
routeConfig
|
|
1012
|
-
} = router.options;
|
|
1013
|
-
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
914
|
+
try {
|
|
915
|
+
throw new Error(message);
|
|
916
|
+
} catch (_unused) {}
|
|
917
|
+
}
|
|
1014
918
|
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
router.routeTree = router.buildRouteTree(routeConfig);
|
|
1018
|
-
}
|
|
919
|
+
return true;
|
|
920
|
+
}
|
|
1019
921
|
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
router.loadLocation(router.parseLocation(event.location, router.location));
|
|
1024
|
-
}),
|
|
1025
|
-
buildRouteTree: rootRouteConfig => {
|
|
1026
|
-
const recurseRoutes = (routeConfigs, parent) => {
|
|
1027
|
-
return routeConfigs.map(routeConfig => {
|
|
1028
|
-
const routeOptions = routeConfig.options;
|
|
1029
|
-
const route = createRoute(routeConfig, routeOptions, parent, router); // {
|
|
1030
|
-
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
1031
|
-
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
1032
|
-
// }
|
|
1033
|
-
|
|
1034
|
-
const existingRoute = router.routesById[route.routeId];
|
|
1035
|
-
|
|
1036
|
-
if (existingRoute) {
|
|
1037
|
-
{
|
|
1038
|
-
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
1039
|
-
}
|
|
922
|
+
function isFunction(d) {
|
|
923
|
+
return typeof d === 'function';
|
|
924
|
+
}
|
|
1040
925
|
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
|
|
1046
|
-
return route;
|
|
1047
|
-
});
|
|
1048
|
-
};
|
|
926
|
+
function functionalUpdate(updater, previous) {
|
|
927
|
+
if (isFunction(updater)) {
|
|
928
|
+
return updater(previous);
|
|
929
|
+
}
|
|
1049
930
|
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
},
|
|
1053
|
-
parseLocation: (location, previousLocation) => {
|
|
1054
|
-
var _location$hash$split$;
|
|
931
|
+
return updater;
|
|
932
|
+
}
|
|
1055
933
|
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
934
|
+
function joinPaths(paths) {
|
|
935
|
+
return cleanPath(paths.filter(Boolean).join('/'));
|
|
936
|
+
}
|
|
937
|
+
function cleanPath(path) {
|
|
938
|
+
// remove double slashes
|
|
939
|
+
return path.replace(/\/{2,}/g, '/');
|
|
940
|
+
}
|
|
941
|
+
function trimPathLeft(path) {
|
|
942
|
+
return path === '/' ? path : path.replace(/^\/{1,}/, '');
|
|
943
|
+
}
|
|
944
|
+
function trimPathRight(path) {
|
|
945
|
+
return path === '/' ? path : path.replace(/\/{1,}$/, '');
|
|
946
|
+
}
|
|
947
|
+
function trimPath(path) {
|
|
948
|
+
return trimPathRight(trimPathLeft(path));
|
|
949
|
+
}
|
|
950
|
+
function resolvePath(basepath, base, to) {
|
|
951
|
+
base = base.replace(new RegExp("^" + basepath), '/');
|
|
952
|
+
to = to.replace(new RegExp("^" + basepath), '/');
|
|
953
|
+
let baseSegments = parsePathname(base);
|
|
954
|
+
const toSegments = parsePathname(to);
|
|
955
|
+
toSegments.forEach((toSegment, index) => {
|
|
956
|
+
if (toSegment.value === '/') {
|
|
957
|
+
if (!index) {
|
|
958
|
+
// Leading slash
|
|
959
|
+
baseSegments = [toSegment];
|
|
960
|
+
} else if (index === toSegments.length - 1) {
|
|
961
|
+
// Trailing Slash
|
|
962
|
+
baseSegments.push(toSegment);
|
|
963
|
+
} else ;
|
|
964
|
+
} else if (toSegment.value === '..') {
|
|
965
|
+
var _last;
|
|
1069
966
|
|
|
1070
|
-
|
|
1071
|
-
|
|
967
|
+
// Extra trailing slash? pop it off
|
|
968
|
+
if (baseSegments.length > 1 && ((_last = last(baseSegments)) == null ? void 0 : _last.value) === '/') {
|
|
969
|
+
baseSegments.pop();
|
|
1072
970
|
}
|
|
1073
971
|
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
972
|
+
baseSegments.pop();
|
|
973
|
+
} else if (toSegment.value === '.') {
|
|
974
|
+
return;
|
|
975
|
+
} else {
|
|
976
|
+
baseSegments.push(toSegment);
|
|
977
|
+
}
|
|
978
|
+
});
|
|
979
|
+
const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
|
|
980
|
+
return cleanPath(joined);
|
|
981
|
+
}
|
|
982
|
+
function parsePathname(pathname) {
|
|
983
|
+
if (!pathname) {
|
|
984
|
+
return [];
|
|
985
|
+
}
|
|
1079
986
|
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
});
|
|
1083
|
-
const toMatches = router.matchRoutes(pathname);
|
|
1084
|
-
const prevParams = (_last = last(fromMatches)) == null ? void 0 : _last.params;
|
|
1085
|
-
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
987
|
+
pathname = cleanPath(pathname);
|
|
988
|
+
const segments = [];
|
|
1086
989
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
990
|
+
if (pathname.slice(0, 1) === '/') {
|
|
991
|
+
pathname = pathname.substring(1);
|
|
992
|
+
segments.push({
|
|
993
|
+
type: 'pathname',
|
|
994
|
+
value: '/'
|
|
995
|
+
});
|
|
996
|
+
}
|
|
1092
997
|
|
|
1093
|
-
|
|
998
|
+
if (!pathname) {
|
|
999
|
+
return segments;
|
|
1000
|
+
} // Remove empty segments and '.' segments
|
|
1094
1001
|
|
|
1095
|
-
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
|
|
1096
1002
|
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1003
|
+
const split = pathname.split('/').filter(Boolean);
|
|
1004
|
+
segments.push(...split.map(part => {
|
|
1005
|
+
if (part.startsWith('*')) {
|
|
1006
|
+
return {
|
|
1007
|
+
type: 'wildcard',
|
|
1008
|
+
value: part
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1101
1011
|
|
|
1102
|
-
|
|
1103
|
-
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
1104
|
-
const searchStr = router.options.stringifySearch(search);
|
|
1105
|
-
let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
|
|
1106
|
-
hash = hash ? "#" + hash : '';
|
|
1012
|
+
if (part.charAt(0) === ':') {
|
|
1107
1013
|
return {
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
searchStr,
|
|
1111
|
-
state: router.location.state,
|
|
1112
|
-
hash,
|
|
1113
|
-
href: "" + pathname + searchStr + hash,
|
|
1114
|
-
key: dest.key
|
|
1014
|
+
type: 'param',
|
|
1015
|
+
value: part
|
|
1115
1016
|
};
|
|
1116
|
-
}
|
|
1117
|
-
commitLocation: (next, replace) => {
|
|
1118
|
-
const id = '' + Date.now() + Math.random();
|
|
1119
|
-
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
1120
|
-
let nextAction = 'replace';
|
|
1017
|
+
}
|
|
1121
1018
|
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1019
|
+
return {
|
|
1020
|
+
type: 'pathname',
|
|
1021
|
+
value: part
|
|
1022
|
+
};
|
|
1023
|
+
}));
|
|
1125
1024
|
|
|
1126
|
-
|
|
1025
|
+
if (pathname.slice(-1) === '/') {
|
|
1026
|
+
pathname = pathname.substring(1);
|
|
1027
|
+
segments.push({
|
|
1028
|
+
type: 'pathname',
|
|
1029
|
+
value: '/'
|
|
1030
|
+
});
|
|
1031
|
+
}
|
|
1127
1032
|
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1033
|
+
return segments;
|
|
1034
|
+
}
|
|
1035
|
+
function interpolatePath(path, params, leaveWildcard) {
|
|
1036
|
+
const interpolatedPathSegments = parsePathname(path);
|
|
1037
|
+
return joinPaths(interpolatedPathSegments.map(segment => {
|
|
1038
|
+
if (segment.value === '*' && !leaveWildcard) {
|
|
1039
|
+
return '';
|
|
1040
|
+
}
|
|
1131
1041
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
pathname: next.pathname,
|
|
1135
|
-
hash: next.hash,
|
|
1136
|
-
search: next.searchStr
|
|
1137
|
-
}, {
|
|
1138
|
-
id
|
|
1139
|
-
});
|
|
1140
|
-
} else {
|
|
1141
|
-
history.push({
|
|
1142
|
-
pathname: next.pathname,
|
|
1143
|
-
hash: next.hash,
|
|
1144
|
-
search: next.searchStr
|
|
1145
|
-
}, {
|
|
1146
|
-
id
|
|
1147
|
-
});
|
|
1148
|
-
}
|
|
1042
|
+
if (segment.type === 'param') {
|
|
1043
|
+
var _segment$value$substr;
|
|
1149
1044
|
|
|
1150
|
-
|
|
1151
|
-
|
|
1045
|
+
return (_segment$value$substr = params[segment.value.substring(1)]) != null ? _segment$value$substr : '';
|
|
1046
|
+
}
|
|
1152
1047
|
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
return router.navigationPromise;
|
|
1159
|
-
},
|
|
1160
|
-
buildNext: opts => {
|
|
1161
|
-
const next = router.buildLocation(opts);
|
|
1162
|
-
const matches = router.matchRoutes(next.pathname);
|
|
1048
|
+
return segment.value;
|
|
1049
|
+
}));
|
|
1050
|
+
}
|
|
1051
|
+
function matchPathname(currentPathname, matchLocation) {
|
|
1052
|
+
const pathParams = matchByPath(currentPathname, matchLocation); // const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
1163
1053
|
|
|
1164
|
-
|
|
1165
|
-
|
|
1054
|
+
if (matchLocation.to && !pathParams) {
|
|
1055
|
+
return;
|
|
1056
|
+
} // if (matchLocation.search && !searchMatched) {
|
|
1057
|
+
// return
|
|
1058
|
+
// }
|
|
1166
1059
|
|
|
1167
|
-
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
1168
|
-
}).flat().filter(Boolean);
|
|
1169
1060
|
|
|
1170
|
-
|
|
1171
|
-
|
|
1061
|
+
return pathParams != null ? pathParams : {};
|
|
1062
|
+
}
|
|
1063
|
+
function matchByPath(from, matchLocation) {
|
|
1064
|
+
var _matchLocation$to;
|
|
1172
1065
|
|
|
1173
|
-
|
|
1174
|
-
|
|
1066
|
+
const baseSegments = parsePathname(from);
|
|
1067
|
+
const routeSegments = parsePathname("" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*'));
|
|
1068
|
+
const params = {};
|
|
1175
1069
|
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
var _router$state$pending, _router$state$pending2;
|
|
1183
|
-
[...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
|
|
1184
|
-
match.cancel();
|
|
1185
|
-
});
|
|
1186
|
-
},
|
|
1187
|
-
loadLocation: async next => {
|
|
1188
|
-
const id = Math.random();
|
|
1189
|
-
router.startedLoadingAt = id;
|
|
1070
|
+
let isMatch = (() => {
|
|
1071
|
+
for (let i = 0; i < Math.max(baseSegments.length, routeSegments.length); i++) {
|
|
1072
|
+
const baseSegment = baseSegments[i];
|
|
1073
|
+
const routeSegment = routeSegments[i];
|
|
1074
|
+
const isLastRouteSegment = i === routeSegments.length - 1;
|
|
1075
|
+
const isLastBaseSegment = i === baseSegments.length - 1;
|
|
1190
1076
|
|
|
1191
|
-
if (
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1077
|
+
if (routeSegment) {
|
|
1078
|
+
if (routeSegment.type === 'wildcard') {
|
|
1079
|
+
if (baseSegment != null && baseSegment.value) {
|
|
1080
|
+
params['*'] = joinPaths(baseSegments.slice(i).map(d => d.value));
|
|
1081
|
+
return true;
|
|
1082
|
+
}
|
|
1195
1083
|
|
|
1084
|
+
return false;
|
|
1085
|
+
}
|
|
1196
1086
|
|
|
1197
|
-
|
|
1087
|
+
if (routeSegment.type === 'pathname') {
|
|
1088
|
+
if (routeSegment.value === '/' && !(baseSegment != null && baseSegment.value)) {
|
|
1089
|
+
return true;
|
|
1090
|
+
}
|
|
1198
1091
|
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
router.state = _extends$1({}, router.state, {
|
|
1209
|
-
pending: {
|
|
1210
|
-
matches: unloadedMatches,
|
|
1211
|
-
location: router.location
|
|
1092
|
+
if (baseSegment) {
|
|
1093
|
+
if (matchLocation.caseSensitive) {
|
|
1094
|
+
if (routeSegment.value !== baseSegment.value) {
|
|
1095
|
+
return false;
|
|
1096
|
+
}
|
|
1097
|
+
} else if (routeSegment.value.toLowerCase() !== baseSegment.value.toLowerCase()) {
|
|
1098
|
+
return false;
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1212
1101
|
}
|
|
1213
|
-
});
|
|
1214
|
-
router.notify(); // Load the matches
|
|
1215
|
-
|
|
1216
|
-
const matches = await router.loadMatches(unloadedMatches, {
|
|
1217
|
-
withPending: true
|
|
1218
|
-
});
|
|
1219
1102
|
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
}
|
|
1103
|
+
if (!baseSegment) {
|
|
1104
|
+
return false;
|
|
1105
|
+
}
|
|
1224
1106
|
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1230
|
-
params: d.params,
|
|
1231
|
-
search: d.routeSearch
|
|
1232
|
-
});
|
|
1233
|
-
});
|
|
1234
|
-
previousMatches.filter(d => {
|
|
1235
|
-
return matches.find(dd => dd.matchId === d.matchId);
|
|
1236
|
-
}).forEach(d => {
|
|
1237
|
-
d.options.onTransition == null ? void 0 : d.options.onTransition({
|
|
1238
|
-
params: d.params,
|
|
1239
|
-
search: d.routeSearch
|
|
1240
|
-
});
|
|
1241
|
-
});
|
|
1242
|
-
matches.filter(d => {
|
|
1243
|
-
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1244
|
-
}).forEach(d => {
|
|
1245
|
-
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1246
|
-
params: d.params,
|
|
1247
|
-
search: d.search
|
|
1248
|
-
});
|
|
1249
|
-
});
|
|
1250
|
-
router.state = _extends$1({}, router.state, {
|
|
1251
|
-
location: router.location,
|
|
1252
|
-
matches,
|
|
1253
|
-
pending: undefined
|
|
1254
|
-
});
|
|
1107
|
+
if (routeSegment.type === 'param') {
|
|
1108
|
+
if ((baseSegment == null ? void 0 : baseSegment.value) === '/') {
|
|
1109
|
+
return false;
|
|
1110
|
+
}
|
|
1255
1111
|
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1112
|
+
if (!baseSegment.value.startsWith(':')) {
|
|
1113
|
+
params[routeSegment.value.substring(1)] = baseSegment.value;
|
|
1114
|
+
}
|
|
1115
|
+
}
|
|
1259
1116
|
}
|
|
1260
1117
|
|
|
1261
|
-
if (
|
|
1262
|
-
|
|
1263
|
-
return;
|
|
1118
|
+
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
1119
|
+
return !!matchLocation.fuzzy;
|
|
1264
1120
|
}
|
|
1121
|
+
}
|
|
1265
1122
|
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
},
|
|
1269
|
-
cleanPreloadCache: () => {
|
|
1270
|
-
const now = Date.now();
|
|
1271
|
-
Object.keys(router.preloadCache).forEach(matchId => {
|
|
1272
|
-
const entry = router.preloadCache[matchId]; // Don't remove loading matches
|
|
1273
|
-
|
|
1274
|
-
if (entry.match.status === 'loading') {
|
|
1275
|
-
return;
|
|
1276
|
-
} // Do not remove successful matches that are still valid
|
|
1277
|
-
|
|
1123
|
+
return true;
|
|
1124
|
+
})();
|
|
1278
1125
|
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
} // Everything else gets removed
|
|
1126
|
+
return isMatch ? params : undefined;
|
|
1127
|
+
}
|
|
1282
1128
|
|
|
1129
|
+
// @ts-nocheck
|
|
1130
|
+
// qss has been slightly modified and inlined here for our use cases (and compression's sake). We've included it as a hard dependency for MIT license attribution.
|
|
1131
|
+
function encode(obj, pfx) {
|
|
1132
|
+
var k,
|
|
1133
|
+
i,
|
|
1134
|
+
tmp,
|
|
1135
|
+
str = '';
|
|
1283
1136
|
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1137
|
+
for (k in obj) {
|
|
1138
|
+
if ((tmp = obj[k]) !== void 0) {
|
|
1139
|
+
if (Array.isArray(tmp)) {
|
|
1140
|
+
for (i = 0; i < tmp.length; i++) {
|
|
1141
|
+
str && (str += '&');
|
|
1142
|
+
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp[i]);
|
|
1143
|
+
}
|
|
1144
|
+
} else {
|
|
1145
|
+
str && (str += '&');
|
|
1146
|
+
str += encodeURIComponent(k) + '=' + encodeURIComponent(tmp);
|
|
1290
1147
|
}
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1291
1150
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
strictParseParams: true
|
|
1295
|
-
});
|
|
1296
|
-
await router.loadMatches(matches, {
|
|
1297
|
-
preload: true,
|
|
1298
|
-
maxAge: loaderOpts.maxAge
|
|
1299
|
-
});
|
|
1300
|
-
return matches;
|
|
1301
|
-
},
|
|
1302
|
-
matchRoutes: (pathname, opts) => {
|
|
1303
|
-
var _router$state$pending3, _router$state$pending4;
|
|
1304
|
-
|
|
1305
|
-
router.cleanPreloadCache();
|
|
1306
|
-
const matches = [];
|
|
1151
|
+
return (pfx || '') + str;
|
|
1152
|
+
}
|
|
1307
1153
|
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
var _parentMatch$params, _router$options$filte, _router$preloadCache$, _route$childRoutes2;
|
|
1316
|
-
|
|
1317
|
-
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
1318
|
-
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
1319
|
-
const route = filteredRoutes == null ? void 0 : filteredRoutes.find(route => {
|
|
1320
|
-
var _route$childRoutes, _route$options$caseSe;
|
|
1321
|
-
|
|
1322
|
-
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length);
|
|
1323
|
-
const matchParams = matchPathname(pathname, {
|
|
1324
|
-
to: route.fullPath,
|
|
1325
|
-
fuzzy,
|
|
1326
|
-
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1327
|
-
});
|
|
1328
|
-
|
|
1329
|
-
if (matchParams) {
|
|
1330
|
-
let parsedParams;
|
|
1331
|
-
|
|
1332
|
-
try {
|
|
1333
|
-
var _route$options$parseP;
|
|
1334
|
-
|
|
1335
|
-
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
1336
|
-
} catch (err) {
|
|
1337
|
-
if (opts != null && opts.strictParseParams) {
|
|
1338
|
-
throw err;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
|
|
1342
|
-
params = _extends$1({}, params, parsedParams);
|
|
1343
|
-
}
|
|
1344
|
-
|
|
1345
|
-
return !!matchParams;
|
|
1346
|
-
});
|
|
1347
|
-
|
|
1348
|
-
if (!route) {
|
|
1349
|
-
return;
|
|
1350
|
-
}
|
|
1351
|
-
|
|
1352
|
-
const interpolatedPath = interpolatePath(route.routePath, params);
|
|
1353
|
-
const matchId = interpolatePath(route.routeId, params, true);
|
|
1354
|
-
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$preloadCache$ = router.preloadCache[matchId]) == null ? void 0 : _router$preloadCache$.match) || createRouteMatch(router, route, {
|
|
1355
|
-
matchId,
|
|
1356
|
-
params,
|
|
1357
|
-
pathname: joinPaths([pathname, interpolatedPath])
|
|
1358
|
-
});
|
|
1359
|
-
matches.push(match);
|
|
1360
|
-
|
|
1361
|
-
if ((_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length) {
|
|
1362
|
-
recurse(route.childRoutes, match);
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
|
|
1366
|
-
recurse([router.routeTree]);
|
|
1367
|
-
return matches;
|
|
1368
|
-
},
|
|
1369
|
-
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
1370
|
-
const matchPromises = resolvedMatches.map(async match => {
|
|
1371
|
-
// Validate the match (loads search params etc)
|
|
1372
|
-
match.__.validate(); // If this is a preload, add it to the preload cache
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
if (loaderOpts != null && loaderOpts.preload) {
|
|
1376
|
-
router.preloadCache[match.matchId] = {
|
|
1377
|
-
maxAge: loaderOpts == null ? void 0 : loaderOpts.maxAge,
|
|
1378
|
-
match
|
|
1379
|
-
};
|
|
1380
|
-
} // If the match is invalid, errored or idle, trigger it to load
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
if (match.status === 'success' && match.isInvalid || match.status === 'error' || match.status === 'idle') {
|
|
1384
|
-
match.load();
|
|
1385
|
-
} // If requested, start the pending timers
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
|
|
1389
|
-
// This might be completion, error, or a pending state
|
|
1390
|
-
|
|
1391
|
-
await match.__.loadPromise;
|
|
1392
|
-
});
|
|
1393
|
-
router.notify();
|
|
1394
|
-
await Promise.all(matchPromises);
|
|
1395
|
-
return resolvedMatches;
|
|
1396
|
-
},
|
|
1397
|
-
invalidateRoute: opts => {
|
|
1398
|
-
var _router$state$pending5, _router$state$pending6;
|
|
1399
|
-
|
|
1400
|
-
const next = router.buildNext(opts);
|
|
1401
|
-
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
1402
|
-
[...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 => {
|
|
1403
|
-
if (unloadedMatchIds.includes(match.matchId)) {
|
|
1404
|
-
match.isInvalid = true;
|
|
1405
|
-
}
|
|
1406
|
-
});
|
|
1407
|
-
},
|
|
1408
|
-
reload: () => router._navigate({
|
|
1409
|
-
fromCurrent: true,
|
|
1410
|
-
replace: true,
|
|
1411
|
-
search: true
|
|
1412
|
-
}),
|
|
1413
|
-
resolvePath: (from, path) => {
|
|
1414
|
-
return _resolvePath(router.basepath, from, cleanPath(path));
|
|
1415
|
-
},
|
|
1416
|
-
matchRoute: (location, opts) => {
|
|
1417
|
-
var _location$from;
|
|
1418
|
-
|
|
1419
|
-
// const location = router.buildNext(opts)
|
|
1420
|
-
location = _extends$1({}, location, {
|
|
1421
|
-
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
1422
|
-
});
|
|
1423
|
-
const next = router.buildNext(location);
|
|
1154
|
+
function toValue(mix) {
|
|
1155
|
+
if (!mix) return '';
|
|
1156
|
+
var str = decodeURIComponent(mix);
|
|
1157
|
+
if (str === 'false') return false;
|
|
1158
|
+
if (str === 'true') return true;
|
|
1159
|
+
return +str * 0 === 0 ? +str : str;
|
|
1160
|
+
}
|
|
1424
1161
|
|
|
1425
|
-
|
|
1426
|
-
|
|
1162
|
+
function decode(str) {
|
|
1163
|
+
var tmp,
|
|
1164
|
+
k,
|
|
1165
|
+
out = {},
|
|
1166
|
+
arr = str.split('&');
|
|
1427
1167
|
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1168
|
+
while (tmp = arr.shift()) {
|
|
1169
|
+
tmp = tmp.split('=');
|
|
1170
|
+
k = tmp.shift();
|
|
1431
1171
|
|
|
1432
|
-
|
|
1433
|
-
|
|
1434
|
-
|
|
1435
|
-
|
|
1172
|
+
if (out[k] !== void 0) {
|
|
1173
|
+
out[k] = [].concat(out[k], toValue(tmp.shift()));
|
|
1174
|
+
} else {
|
|
1175
|
+
out[k] = toValue(tmp.shift());
|
|
1176
|
+
}
|
|
1177
|
+
}
|
|
1436
1178
|
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
}));
|
|
1440
|
-
},
|
|
1441
|
-
_navigate: location => {
|
|
1442
|
-
const next = router.buildNext(location);
|
|
1443
|
-
return router.commitLocation(next, location.replace);
|
|
1444
|
-
},
|
|
1445
|
-
navigate: async _ref => {
|
|
1446
|
-
let {
|
|
1447
|
-
from,
|
|
1448
|
-
to = '.',
|
|
1449
|
-
search,
|
|
1450
|
-
hash,
|
|
1451
|
-
replace
|
|
1452
|
-
} = _ref;
|
|
1453
|
-
// If this link simply reloads the current route,
|
|
1454
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
1455
|
-
// If this `to` is a valid external URL, return
|
|
1456
|
-
// null for LinkUtils
|
|
1457
|
-
const toString = String(to);
|
|
1458
|
-
const fromString = String(from);
|
|
1459
|
-
let isExternal;
|
|
1179
|
+
return out;
|
|
1180
|
+
}
|
|
1460
1181
|
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1182
|
+
function _extends() {
|
|
1183
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
1184
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
1185
|
+
var source = arguments[i];
|
|
1465
1186
|
|
|
1466
|
-
|
|
1467
|
-
{
|
|
1468
|
-
|
|
1187
|
+
for (var key in source) {
|
|
1188
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
1189
|
+
target[key] = source[key];
|
|
1469
1190
|
}
|
|
1470
1191
|
}
|
|
1471
|
-
|
|
1472
|
-
return router._navigate({
|
|
1473
|
-
from: fromString,
|
|
1474
|
-
to: toString,
|
|
1475
|
-
search,
|
|
1476
|
-
hash
|
|
1477
|
-
});
|
|
1478
|
-
},
|
|
1479
|
-
buildLink: _ref2 => {
|
|
1480
|
-
var _preload, _ref3, _ref4;
|
|
1481
|
-
|
|
1482
|
-
let {
|
|
1483
|
-
from,
|
|
1484
|
-
to = '.',
|
|
1485
|
-
search,
|
|
1486
|
-
params,
|
|
1487
|
-
hash,
|
|
1488
|
-
target,
|
|
1489
|
-
replace,
|
|
1490
|
-
activeOptions,
|
|
1491
|
-
preload,
|
|
1492
|
-
preloadMaxAge: userPreloadMaxAge,
|
|
1493
|
-
preloadDelay: userPreloadDelay,
|
|
1494
|
-
disabled
|
|
1495
|
-
} = _ref2;
|
|
1496
|
-
|
|
1497
|
-
// If this link simply reloads the current route,
|
|
1498
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
1499
|
-
// If this `to` is a valid external URL, return
|
|
1500
|
-
// null for LinkUtils
|
|
1501
|
-
try {
|
|
1502
|
-
new URL("" + to);
|
|
1503
|
-
return {
|
|
1504
|
-
type: 'external',
|
|
1505
|
-
href: to
|
|
1506
|
-
};
|
|
1507
|
-
} catch (e) {}
|
|
1508
|
-
|
|
1509
|
-
const nextOpts = {
|
|
1510
|
-
from,
|
|
1511
|
-
to,
|
|
1512
|
-
search,
|
|
1513
|
-
params,
|
|
1514
|
-
hash,
|
|
1515
|
-
replace
|
|
1516
|
-
};
|
|
1517
|
-
const next = router.buildNext(nextOpts);
|
|
1518
|
-
preload = (_preload = preload) != null ? _preload : router.options.defaultLinkPreload;
|
|
1519
|
-
const preloadMaxAge = (_ref3 = userPreloadMaxAge != null ? userPreloadMaxAge : router.options.defaultLinkPreloadMaxAge) != null ? _ref3 : 2000;
|
|
1520
|
-
const preloadDelay = (_ref4 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultLinkPreloadDelay) != null ? _ref4 : 50; // Compare path/hash for matches
|
|
1521
|
-
|
|
1522
|
-
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
1523
|
-
const currentPathSplit = router.state.location.pathname.split('/');
|
|
1524
|
-
const nextPathSplit = next.pathname.split('/');
|
|
1525
|
-
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
1526
|
-
const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
|
|
1527
|
-
|
|
1528
|
-
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
1529
|
-
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
|
|
1530
|
-
|
|
1531
|
-
const isActive = pathTest && hashTest; // The click handler
|
|
1532
|
-
|
|
1533
|
-
const handleClick = e => {
|
|
1534
|
-
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
1535
|
-
e.preventDefault();
|
|
1536
|
-
|
|
1537
|
-
if (pathIsEqual && !search && !hash) {
|
|
1538
|
-
router.invalidateRoute(nextOpts);
|
|
1539
|
-
} // All is well? Navigate!)
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
router._navigate(nextOpts);
|
|
1543
|
-
}
|
|
1544
|
-
}; // The click handler
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
const handleFocus = e => {
|
|
1548
|
-
if (preload && preloadMaxAge > 0) {
|
|
1549
|
-
router.loadRoute(nextOpts, {
|
|
1550
|
-
maxAge: preloadMaxAge
|
|
1551
|
-
});
|
|
1552
|
-
}
|
|
1553
|
-
};
|
|
1554
|
-
|
|
1555
|
-
const handleEnter = e => {
|
|
1556
|
-
const target = e.target || {};
|
|
1557
|
-
|
|
1558
|
-
if (preload && preloadMaxAge > 0) {
|
|
1559
|
-
if (target.preloadTimeout) {
|
|
1560
|
-
return;
|
|
1561
|
-
}
|
|
1562
|
-
|
|
1563
|
-
target.preloadTimeout = setTimeout(() => {
|
|
1564
|
-
target.preloadTimeout = null;
|
|
1565
|
-
router.loadRoute(nextOpts, {
|
|
1566
|
-
maxAge: preloadMaxAge
|
|
1567
|
-
});
|
|
1568
|
-
}, preloadDelay);
|
|
1569
|
-
}
|
|
1570
|
-
};
|
|
1571
|
-
|
|
1572
|
-
const handleLeave = e => {
|
|
1573
|
-
const target = e.target || {};
|
|
1574
|
-
|
|
1575
|
-
if (target.preloadTimeout) {
|
|
1576
|
-
clearTimeout(target.preloadTimeout);
|
|
1577
|
-
target.preloadTimeout = null;
|
|
1578
|
-
}
|
|
1579
|
-
};
|
|
1580
|
-
|
|
1581
|
-
return {
|
|
1582
|
-
type: 'internal',
|
|
1583
|
-
next,
|
|
1584
|
-
handleFocus,
|
|
1585
|
-
handleClick,
|
|
1586
|
-
handleEnter,
|
|
1587
|
-
handleLeave,
|
|
1588
|
-
isActive,
|
|
1589
|
-
disabled
|
|
1590
|
-
};
|
|
1591
|
-
},
|
|
1592
|
-
__experimental__createSnapshot: () => {
|
|
1593
|
-
return _extends$1({}, router.state, {
|
|
1594
|
-
matches: router.state.matches.map(_ref5 => {
|
|
1595
|
-
let {
|
|
1596
|
-
routeLoaderData: loaderData,
|
|
1597
|
-
matchId
|
|
1598
|
-
} = _ref5;
|
|
1599
|
-
return {
|
|
1600
|
-
matchId,
|
|
1601
|
-
loaderData
|
|
1602
|
-
};
|
|
1603
|
-
})
|
|
1604
|
-
});
|
|
1605
1192
|
}
|
|
1606
|
-
};
|
|
1607
|
-
router.location = router.parseLocation(history.location); // router.state.location = __experimental__snapshot?.location ?? router.location
|
|
1608
|
-
|
|
1609
|
-
router.state.location = router.location;
|
|
1610
|
-
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
1611
1193
|
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
return
|
|
1194
|
+
return target;
|
|
1195
|
+
};
|
|
1196
|
+
return _extends.apply(this, arguments);
|
|
1615
1197
|
}
|
|
1198
|
+
|
|
1616
1199
|
function createRoute(routeConfig, options, parent, router) {
|
|
1617
|
-
// const id = (
|
|
1618
|
-
// options.path === rootRouteId
|
|
1619
|
-
// ? rootRouteId
|
|
1620
|
-
// : joinPaths([
|
|
1621
|
-
// parent!.id,
|
|
1622
|
-
// `${options.path?.replace(/(.)\/$/, '$1')}`,
|
|
1623
|
-
// ]).replace(new RegExp(`^${rootRouteId}`), '')
|
|
1624
|
-
// ) as TRouteInfo['id']
|
|
1625
1200
|
const {
|
|
1626
|
-
id
|
|
1201
|
+
id,
|
|
1202
|
+
routeId,
|
|
1627
1203
|
path: routePath,
|
|
1628
1204
|
fullPath
|
|
1629
1205
|
} = routeConfig;
|
|
1630
1206
|
|
|
1631
|
-
const action = router.state.actions[
|
|
1632
|
-
router.state.actions[
|
|
1207
|
+
const action = router.state.actions[id] || (() => {
|
|
1208
|
+
router.state.actions[id] = {
|
|
1633
1209
|
pending: [],
|
|
1634
1210
|
submit: async (submission, actionOpts) => {
|
|
1635
1211
|
var _actionOpts$invalidat;
|
|
@@ -1644,10 +1220,12 @@
|
|
|
1644
1220
|
status: 'pending',
|
|
1645
1221
|
submission
|
|
1646
1222
|
};
|
|
1223
|
+
action.current = actionState;
|
|
1647
1224
|
action.latest = actionState;
|
|
1648
1225
|
action.pending.push(actionState);
|
|
1649
|
-
router.state = _extends
|
|
1650
|
-
|
|
1226
|
+
router.state = _extends({}, router.state, {
|
|
1227
|
+
currentAction: actionState,
|
|
1228
|
+
latestAction: actionState
|
|
1651
1229
|
});
|
|
1652
1230
|
router.notify();
|
|
1653
1231
|
|
|
@@ -1671,20 +1249,20 @@
|
|
|
1671
1249
|
actionState.status = 'error';
|
|
1672
1250
|
} finally {
|
|
1673
1251
|
action.pending = action.pending.filter(d => d !== actionState);
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
}
|
|
1678
|
-
|
|
1252
|
+
router.removeActionQueue.push({
|
|
1253
|
+
action,
|
|
1254
|
+
actionState
|
|
1255
|
+
});
|
|
1679
1256
|
router.notify();
|
|
1680
1257
|
}
|
|
1681
1258
|
}
|
|
1682
1259
|
};
|
|
1683
|
-
return router.state.actions[
|
|
1260
|
+
return router.state.actions[id];
|
|
1684
1261
|
})();
|
|
1685
1262
|
|
|
1686
1263
|
let route = {
|
|
1687
|
-
routeId,
|
|
1264
|
+
routeId: id,
|
|
1265
|
+
routeRouteId: routeId,
|
|
1688
1266
|
routePath,
|
|
1689
1267
|
fullPath,
|
|
1690
1268
|
options,
|
|
@@ -1693,17 +1271,17 @@
|
|
|
1693
1271
|
parentRoute: parent,
|
|
1694
1272
|
action,
|
|
1695
1273
|
buildLink: options => {
|
|
1696
|
-
return router.buildLink(_extends
|
|
1274
|
+
return router.buildLink(_extends({}, options, {
|
|
1697
1275
|
from: fullPath
|
|
1698
1276
|
}));
|
|
1699
1277
|
},
|
|
1700
1278
|
navigate: options => {
|
|
1701
|
-
return router.navigate(_extends
|
|
1279
|
+
return router.navigate(_extends({}, options, {
|
|
1702
1280
|
from: fullPath
|
|
1703
1281
|
}));
|
|
1704
1282
|
},
|
|
1705
1283
|
matchRoute: (matchLocation, opts) => {
|
|
1706
|
-
return router.matchRoute(_extends
|
|
1284
|
+
return router.matchRoute(_extends({}, matchLocation, {
|
|
1707
1285
|
from: fullPath
|
|
1708
1286
|
}), opts);
|
|
1709
1287
|
}
|
|
@@ -1714,8 +1292,69 @@
|
|
|
1714
1292
|
});
|
|
1715
1293
|
return route;
|
|
1716
1294
|
}
|
|
1295
|
+
function cascadeLoaderData(matches) {
|
|
1296
|
+
matches.forEach((match, index) => {
|
|
1297
|
+
const parent = matches[index - 1];
|
|
1298
|
+
|
|
1299
|
+
if (parent) {
|
|
1300
|
+
match.loaderData = replaceEqualDeep(match.loaderData, _extends({}, parent.loaderData, match.routeLoaderData));
|
|
1301
|
+
}
|
|
1302
|
+
});
|
|
1303
|
+
}
|
|
1304
|
+
|
|
1305
|
+
const rootRouteId = '__root__';
|
|
1306
|
+
const createRouteConfig = function createRouteConfig(options, children, isRoot, parentId, parentPath) {
|
|
1307
|
+
if (options === void 0) {
|
|
1308
|
+
options = {};
|
|
1309
|
+
}
|
|
1310
|
+
|
|
1311
|
+
if (isRoot === void 0) {
|
|
1312
|
+
isRoot = true;
|
|
1313
|
+
}
|
|
1314
|
+
|
|
1315
|
+
if (isRoot) {
|
|
1316
|
+
options.path = rootRouteId;
|
|
1317
|
+
} // Strip the root from parentIds
|
|
1318
|
+
|
|
1319
|
+
|
|
1320
|
+
if (parentId === rootRouteId) {
|
|
1321
|
+
parentId = '';
|
|
1322
|
+
}
|
|
1323
|
+
|
|
1324
|
+
let path = isRoot ? rootRouteId : options.path; // If the path is anything other than an index path, trim it up
|
|
1325
|
+
|
|
1326
|
+
if (path && path !== '/') {
|
|
1327
|
+
path = trimPath(path);
|
|
1328
|
+
}
|
|
1329
|
+
|
|
1330
|
+
const routeId = path || options.id;
|
|
1331
|
+
let id = joinPaths([parentId, routeId]);
|
|
1332
|
+
|
|
1333
|
+
if (path === rootRouteId) {
|
|
1334
|
+
path = '/';
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
if (id !== rootRouteId) {
|
|
1338
|
+
id = joinPaths(['/', id]);
|
|
1339
|
+
}
|
|
1340
|
+
|
|
1341
|
+
const fullPath = id === rootRouteId ? '/' : trimPathRight(joinPaths([parentPath, path]));
|
|
1342
|
+
return {
|
|
1343
|
+
id: id,
|
|
1344
|
+
routeId: routeId,
|
|
1345
|
+
path: path,
|
|
1346
|
+
fullPath: fullPath,
|
|
1347
|
+
options: options,
|
|
1348
|
+
children,
|
|
1349
|
+
createChildren: cb => createRouteConfig(options, cb(childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)), false, parentId, parentPath),
|
|
1350
|
+
addChildren: children => createRouteConfig(options, children, false, parentId, parentPath),
|
|
1351
|
+
createRoute: childOptions => createRouteConfig(childOptions, undefined, false, id, fullPath)
|
|
1352
|
+
};
|
|
1353
|
+
};
|
|
1354
|
+
|
|
1355
|
+
const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
|
|
1717
1356
|
function createRouteMatch(router, route, opts) {
|
|
1718
|
-
const routeMatch = _extends
|
|
1357
|
+
const routeMatch = _extends({}, route, opts, {
|
|
1719
1358
|
router,
|
|
1720
1359
|
routeSearch: {},
|
|
1721
1360
|
search: {},
|
|
@@ -1726,6 +1365,11 @@
|
|
|
1726
1365
|
isPending: false,
|
|
1727
1366
|
isFetching: false,
|
|
1728
1367
|
isInvalid: false,
|
|
1368
|
+
invalidAt: Infinity,
|
|
1369
|
+
getIsInvalid: () => {
|
|
1370
|
+
const now = Date.now();
|
|
1371
|
+
return routeMatch.isInvalid || routeMatch.invalidAt < now;
|
|
1372
|
+
},
|
|
1729
1373
|
__: {
|
|
1730
1374
|
abortController: new AbortController(),
|
|
1731
1375
|
latestId: '',
|
|
@@ -1761,16 +1405,17 @@
|
|
|
1761
1405
|
clearTimeout(routeMatch.__.pendingMinTimeout);
|
|
1762
1406
|
delete routeMatch.__.pendingMinPromise;
|
|
1763
1407
|
},
|
|
1764
|
-
setParentMatch: parentMatch => {
|
|
1765
|
-
|
|
1766
|
-
},
|
|
1767
|
-
addChildMatch: childMatch => {
|
|
1768
|
-
|
|
1769
|
-
|
|
1770
|
-
|
|
1771
|
-
|
|
1772
|
-
|
|
1773
|
-
|
|
1408
|
+
// setParentMatch: (parentMatch?: RouteMatch) => {
|
|
1409
|
+
// routeMatch.parentMatch = parentMatch
|
|
1410
|
+
// },
|
|
1411
|
+
// addChildMatch: (childMatch: RouteMatch) => {
|
|
1412
|
+
// if (
|
|
1413
|
+
// routeMatch.childMatches.find((d) => d.matchId === childMatch.matchId)
|
|
1414
|
+
// ) {
|
|
1415
|
+
// return
|
|
1416
|
+
// }
|
|
1417
|
+
// routeMatch.childMatches.push(childMatch)
|
|
1418
|
+
// },
|
|
1774
1419
|
validate: () => {
|
|
1775
1420
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1776
1421
|
|
|
@@ -1779,14 +1424,15 @@
|
|
|
1779
1424
|
|
|
1780
1425
|
try {
|
|
1781
1426
|
const prevSearch = routeMatch.routeSearch;
|
|
1782
|
-
|
|
1427
|
+
const validator = typeof routeMatch.options.validateSearch === 'object' ? routeMatch.options.validateSearch.parse : routeMatch.options.validateSearch;
|
|
1428
|
+
let nextSearch = replaceEqualDeep(prevSearch, validator == null ? void 0 : validator(parentSearch)); // Invalidate route matches when search param stability changes
|
|
1783
1429
|
|
|
1784
1430
|
if (prevSearch !== nextSearch) {
|
|
1785
1431
|
routeMatch.isInvalid = true;
|
|
1786
1432
|
}
|
|
1787
1433
|
|
|
1788
1434
|
routeMatch.routeSearch = nextSearch;
|
|
1789
|
-
routeMatch.search = replaceEqualDeep(parentSearch, _extends
|
|
1435
|
+
routeMatch.search = replaceEqualDeep(parentSearch, _extends({}, parentSearch, nextSearch));
|
|
1790
1436
|
} catch (err) {
|
|
1791
1437
|
console.error(err);
|
|
1792
1438
|
const error = new Error('Invalid search params found', {
|
|
@@ -1807,13 +1453,19 @@
|
|
|
1807
1453
|
|
|
1808
1454
|
routeMatch.__.cancelPending();
|
|
1809
1455
|
},
|
|
1810
|
-
|
|
1456
|
+
invalidate: () => {
|
|
1457
|
+
routeMatch.isInvalid = true;
|
|
1458
|
+
},
|
|
1459
|
+
hasLoaders: () => {
|
|
1460
|
+
return !!(route.options.loader || elementTypes.some(d => typeof route.options[d] === 'function'));
|
|
1461
|
+
},
|
|
1462
|
+
load: async opts => {
|
|
1811
1463
|
const id = '' + Date.now() + Math.random();
|
|
1812
1464
|
routeMatch.__.latestId = id; // If the match was in an error state, set it
|
|
1813
1465
|
// to a loading state again. Otherwise, keep it
|
|
1814
1466
|
// as loading or resolved
|
|
1815
1467
|
|
|
1816
|
-
if (routeMatch.status === '
|
|
1468
|
+
if (routeMatch.status === 'idle') {
|
|
1817
1469
|
routeMatch.status = 'loading';
|
|
1818
1470
|
} // We started loading the route, so it's no longer invalid
|
|
1819
1471
|
|
|
@@ -1826,25 +1478,10 @@
|
|
|
1826
1478
|
routeMatch.__.resolve = resolve;
|
|
1827
1479
|
|
|
1828
1480
|
const loaderPromise = (async () => {
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
if (importer) {
|
|
1832
|
-
routeMatch.__.importPromise = importer({
|
|
1833
|
-
params: routeMatch.params // search: routeMatch.search,
|
|
1834
|
-
|
|
1835
|
-
}).then(imported => {
|
|
1836
|
-
routeMatch.__ = _extends$1({}, routeMatch.__, imported);
|
|
1837
|
-
});
|
|
1838
|
-
} // Wait for the importer to finish before
|
|
1839
|
-
// attempting to load elements and data
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
await routeMatch.__.importPromise; // Next, load the elements and data in parallel
|
|
1843
|
-
|
|
1481
|
+
// Load the elements and data in parallel
|
|
1844
1482
|
routeMatch.__.elementsPromise = (async () => {
|
|
1845
1483
|
// then run all element and data loaders in parallel
|
|
1846
1484
|
// For each element type, potentially load it asynchronously
|
|
1847
|
-
const elementTypes = ['element', 'errorElement', 'catchElement', 'pendingElement'];
|
|
1848
1485
|
await Promise.all(elementTypes.map(async type => {
|
|
1849
1486
|
const routeElement = routeMatch.options[type];
|
|
1850
1487
|
|
|
@@ -1863,21 +1500,26 @@
|
|
|
1863
1500
|
|
|
1864
1501
|
routeMatch.__.dataPromise = Promise.resolve().then(async () => {
|
|
1865
1502
|
try {
|
|
1866
|
-
|
|
1867
|
-
params: routeMatch.params,
|
|
1868
|
-
search: routeMatch.routeSearch,
|
|
1869
|
-
signal: routeMatch.__.abortController.signal
|
|
1870
|
-
}));
|
|
1503
|
+
var _ref, _ref2, _opts$maxAge;
|
|
1871
1504
|
|
|
1872
|
-
if (
|
|
1873
|
-
|
|
1505
|
+
if (routeMatch.options.loader) {
|
|
1506
|
+
const data = await routeMatch.options.loader({
|
|
1507
|
+
params: routeMatch.params,
|
|
1508
|
+
search: routeMatch.routeSearch,
|
|
1509
|
+
signal: routeMatch.__.abortController.signal
|
|
1510
|
+
});
|
|
1511
|
+
|
|
1512
|
+
if (id !== routeMatch.__.latestId) {
|
|
1513
|
+
return routeMatch.__.loaderPromise;
|
|
1514
|
+
}
|
|
1515
|
+
|
|
1516
|
+
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1874
1517
|
}
|
|
1875
1518
|
|
|
1876
|
-
routeMatch.routeLoaderData = replaceEqualDeep(routeMatch.routeLoaderData, data);
|
|
1877
|
-
cascadeLoaderData(routeMatch);
|
|
1878
1519
|
routeMatch.error = undefined;
|
|
1879
1520
|
routeMatch.status = 'success';
|
|
1880
1521
|
routeMatch.updatedAt = Date.now();
|
|
1522
|
+
routeMatch.invalidAt = routeMatch.updatedAt + ((_ref = (_ref2 = (_opts$maxAge = opts == null ? void 0 : opts.maxAge) != null ? _opts$maxAge : routeMatch.options.loaderMaxAge) != null ? _ref2 : router.options.defaultLoaderMaxAge) != null ? _ref : 0);
|
|
1881
1523
|
} catch (err) {
|
|
1882
1524
|
if (id !== routeMatch.__.latestId) {
|
|
1883
1525
|
return routeMatch.__.loaderPromise;
|
|
@@ -1896,405 +1538,882 @@
|
|
|
1896
1538
|
try {
|
|
1897
1539
|
await Promise.all([routeMatch.__.elementsPromise, routeMatch.__.dataPromise]);
|
|
1898
1540
|
|
|
1899
|
-
if (id !== routeMatch.__.latestId) {
|
|
1900
|
-
return routeMatch.__.loaderPromise;
|
|
1901
|
-
}
|
|
1541
|
+
if (id !== routeMatch.__.latestId) {
|
|
1542
|
+
return routeMatch.__.loaderPromise;
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1545
|
+
if (routeMatch.__.pendingMinPromise) {
|
|
1546
|
+
await routeMatch.__.pendingMinPromise;
|
|
1547
|
+
delete routeMatch.__.pendingMinPromise;
|
|
1548
|
+
}
|
|
1549
|
+
} finally {
|
|
1550
|
+
if (id !== routeMatch.__.latestId) {
|
|
1551
|
+
return routeMatch.__.loaderPromise;
|
|
1552
|
+
}
|
|
1553
|
+
|
|
1554
|
+
routeMatch.__.cancelPending();
|
|
1555
|
+
|
|
1556
|
+
routeMatch.isPending = false;
|
|
1557
|
+
routeMatch.isFetching = false;
|
|
1558
|
+
|
|
1559
|
+
routeMatch.__.notify();
|
|
1560
|
+
}
|
|
1561
|
+
})();
|
|
1562
|
+
|
|
1563
|
+
routeMatch.__.loaderPromise = loaderPromise;
|
|
1564
|
+
await loaderPromise;
|
|
1565
|
+
|
|
1566
|
+
if (id !== routeMatch.__.latestId) {
|
|
1567
|
+
return routeMatch.__.loaderPromise;
|
|
1568
|
+
}
|
|
1569
|
+
|
|
1570
|
+
delete routeMatch.__.loaderPromise;
|
|
1571
|
+
});
|
|
1572
|
+
return await routeMatch.__.loadPromise;
|
|
1573
|
+
}
|
|
1574
|
+
});
|
|
1575
|
+
|
|
1576
|
+
if (!routeMatch.hasLoaders()) {
|
|
1577
|
+
routeMatch.status = 'success';
|
|
1578
|
+
}
|
|
1579
|
+
|
|
1580
|
+
return routeMatch;
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
const defaultParseSearch = parseSearchWith(JSON.parse);
|
|
1584
|
+
const defaultStringifySearch = stringifySearchWith(JSON.stringify);
|
|
1585
|
+
function parseSearchWith(parser) {
|
|
1586
|
+
return searchStr => {
|
|
1587
|
+
if (searchStr.substring(0, 1) === '?') {
|
|
1588
|
+
searchStr = searchStr.substring(1);
|
|
1589
|
+
}
|
|
1590
|
+
|
|
1591
|
+
let query = decode(searchStr); // Try to parse any query params that might be json
|
|
1592
|
+
|
|
1593
|
+
for (let key in query) {
|
|
1594
|
+
const value = query[key];
|
|
1595
|
+
|
|
1596
|
+
if (typeof value === 'string') {
|
|
1597
|
+
try {
|
|
1598
|
+
query[key] = parser(value);
|
|
1599
|
+
} catch (err) {//
|
|
1600
|
+
}
|
|
1601
|
+
}
|
|
1602
|
+
}
|
|
1603
|
+
|
|
1604
|
+
return query;
|
|
1605
|
+
};
|
|
1606
|
+
}
|
|
1607
|
+
function stringifySearchWith(stringify) {
|
|
1608
|
+
return search => {
|
|
1609
|
+
search = _extends({}, search);
|
|
1610
|
+
|
|
1611
|
+
if (search) {
|
|
1612
|
+
Object.keys(search).forEach(key => {
|
|
1613
|
+
const val = search[key];
|
|
1614
|
+
|
|
1615
|
+
if (typeof val === 'undefined' || val === undefined) {
|
|
1616
|
+
delete search[key];
|
|
1617
|
+
} else if (val && typeof val === 'object' && val !== null) {
|
|
1618
|
+
try {
|
|
1619
|
+
search[key] = stringify(val);
|
|
1620
|
+
} catch (err) {// silent
|
|
1621
|
+
}
|
|
1622
|
+
}
|
|
1623
|
+
});
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
const searchStr = encode(search).toString();
|
|
1627
|
+
return searchStr ? "?" + searchStr : '';
|
|
1628
|
+
};
|
|
1629
|
+
}
|
|
1630
|
+
|
|
1631
|
+
var _window$document;
|
|
1632
|
+
// Detect if we're in the DOM
|
|
1633
|
+
const isServer = Boolean(typeof window === 'undefined' || !((_window$document = window.document) != null && _window$document.createElement)); // This is the default history object if none is defined
|
|
1634
|
+
|
|
1635
|
+
const createDefaultHistory = () => !isServer ? createBrowserHistory() : createMemoryHistory();
|
|
1636
|
+
|
|
1637
|
+
function createRouter(userOptions) {
|
|
1638
|
+
var _userOptions$stringif, _userOptions$parseSea;
|
|
1639
|
+
|
|
1640
|
+
const history = (userOptions == null ? void 0 : userOptions.history) || createDefaultHistory();
|
|
1641
|
+
|
|
1642
|
+
const originalOptions = _extends({
|
|
1643
|
+
defaultLoaderGcMaxAge: 5 * 60 * 1000,
|
|
1644
|
+
defaultLoaderMaxAge: 0,
|
|
1645
|
+
defaultPreloadMaxAge: 2000,
|
|
1646
|
+
defaultPreloadDelay: 50
|
|
1647
|
+
}, userOptions, {
|
|
1648
|
+
stringifySearch: (_userOptions$stringif = userOptions == null ? void 0 : userOptions.stringifySearch) != null ? _userOptions$stringif : defaultStringifySearch,
|
|
1649
|
+
parseSearch: (_userOptions$parseSea = userOptions == null ? void 0 : userOptions.parseSearch) != null ? _userOptions$parseSea : defaultParseSearch
|
|
1650
|
+
});
|
|
1651
|
+
|
|
1652
|
+
let router = {
|
|
1653
|
+
history,
|
|
1654
|
+
options: originalOptions,
|
|
1655
|
+
listeners: [],
|
|
1656
|
+
removeActionQueue: [],
|
|
1657
|
+
// Resolved after construction
|
|
1658
|
+
basepath: '',
|
|
1659
|
+
routeTree: undefined,
|
|
1660
|
+
routesById: {},
|
|
1661
|
+
location: undefined,
|
|
1662
|
+
allRouteInfo: undefined,
|
|
1663
|
+
//
|
|
1664
|
+
navigationPromise: Promise.resolve(),
|
|
1665
|
+
resolveNavigation: () => {},
|
|
1666
|
+
matchCache: {},
|
|
1667
|
+
state: {
|
|
1668
|
+
status: 'idle',
|
|
1669
|
+
location: null,
|
|
1670
|
+
matches: [],
|
|
1671
|
+
actions: {},
|
|
1672
|
+
loaderData: {},
|
|
1673
|
+
lastUpdated: Date.now(),
|
|
1674
|
+
isFetching: false,
|
|
1675
|
+
isPreloading: false
|
|
1676
|
+
},
|
|
1677
|
+
startedLoadingAt: Date.now(),
|
|
1678
|
+
subscribe: listener => {
|
|
1679
|
+
router.listeners.push(listener);
|
|
1680
|
+
return () => {
|
|
1681
|
+
router.listeners = router.listeners.filter(x => x !== listener);
|
|
1682
|
+
};
|
|
1683
|
+
},
|
|
1684
|
+
getRoute: id => {
|
|
1685
|
+
return router.routesById[id];
|
|
1686
|
+
},
|
|
1687
|
+
notify: () => {
|
|
1688
|
+
router.state = _extends({}, router.state, {
|
|
1689
|
+
isFetching: router.state.status === 'loading' || router.state.matches.some(d => d.isFetching),
|
|
1690
|
+
isPreloading: Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.matches.find(dd => dd.matchId === d.match.matchId))
|
|
1691
|
+
});
|
|
1692
|
+
cascadeLoaderData(router.state.matches);
|
|
1693
|
+
router.listeners.forEach(listener => listener());
|
|
1694
|
+
},
|
|
1695
|
+
mount: () => {
|
|
1696
|
+
const next = router.__.buildLocation({
|
|
1697
|
+
to: '.',
|
|
1698
|
+
search: true,
|
|
1699
|
+
hash: true
|
|
1700
|
+
}); // If the current location isn't updated, trigger a navigation
|
|
1701
|
+
// to the current location. Otherwise, load the current location.
|
|
1702
|
+
|
|
1703
|
+
|
|
1704
|
+
if (next.href !== router.location.href) {
|
|
1705
|
+
router.__.commitLocation(next, true);
|
|
1706
|
+
} else {
|
|
1707
|
+
router.loadLocation();
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
const unsub = history.listen(event => {
|
|
1711
|
+
router.loadLocation(router.__.parseLocation(event.location, router.location));
|
|
1712
|
+
}); // addEventListener does not exist in React Native, but window does
|
|
1713
|
+
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
|
|
1714
|
+
|
|
1715
|
+
if (!isServer && window.addEventListener) {
|
|
1716
|
+
// Listen to visibillitychange and focus
|
|
1717
|
+
window.addEventListener('visibilitychange', router.onFocus, false);
|
|
1718
|
+
window.addEventListener('focus', router.onFocus, false);
|
|
1719
|
+
}
|
|
1720
|
+
|
|
1721
|
+
return () => {
|
|
1722
|
+
unsub(); // Be sure to unsubscribe if a new handler is set
|
|
1723
|
+
|
|
1724
|
+
window.removeEventListener('visibilitychange', router.onFocus);
|
|
1725
|
+
window.removeEventListener('focus', router.onFocus);
|
|
1726
|
+
};
|
|
1727
|
+
},
|
|
1728
|
+
onFocus: () => {
|
|
1729
|
+
router.loadLocation();
|
|
1730
|
+
},
|
|
1731
|
+
update: opts => {
|
|
1732
|
+
Object.assign(router.options, opts);
|
|
1733
|
+
const {
|
|
1734
|
+
basepath,
|
|
1735
|
+
routeConfig
|
|
1736
|
+
} = router.options;
|
|
1737
|
+
router.basepath = cleanPath("/" + (basepath != null ? basepath : ''));
|
|
1738
|
+
|
|
1739
|
+
if (routeConfig) {
|
|
1740
|
+
router.routesById = {};
|
|
1741
|
+
router.routeTree = router.__.buildRouteTree(routeConfig);
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
return router;
|
|
1745
|
+
},
|
|
1746
|
+
cancelMatches: () => {
|
|
1747
|
+
var _router$state$pending, _router$state$pending2;
|
|
1748
|
+
[...router.state.matches, ...((_router$state$pending = (_router$state$pending2 = router.state.pending) == null ? void 0 : _router$state$pending2.matches) != null ? _router$state$pending : [])].forEach(match => {
|
|
1749
|
+
match.cancel();
|
|
1750
|
+
});
|
|
1751
|
+
},
|
|
1752
|
+
loadLocation: async next => {
|
|
1753
|
+
const id = Math.random();
|
|
1754
|
+
router.startedLoadingAt = id;
|
|
1755
|
+
|
|
1756
|
+
if (next) {
|
|
1757
|
+
// Ingest the new location
|
|
1758
|
+
router.location = next;
|
|
1759
|
+
} // Clear out old actions
|
|
1760
|
+
|
|
1761
|
+
|
|
1762
|
+
router.removeActionQueue.forEach(_ref => {
|
|
1763
|
+
let {
|
|
1764
|
+
action,
|
|
1765
|
+
actionState
|
|
1766
|
+
} = _ref;
|
|
1767
|
+
|
|
1768
|
+
if (router.state.currentAction === actionState) {
|
|
1769
|
+
router.state.currentAction = undefined;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
if (action.current === actionState) {
|
|
1773
|
+
action.current = undefined;
|
|
1774
|
+
}
|
|
1775
|
+
});
|
|
1776
|
+
router.removeActionQueue = []; // Cancel any pending matches
|
|
1777
|
+
|
|
1778
|
+
router.cancelMatches(); // Match the routes
|
|
1779
|
+
|
|
1780
|
+
const matches = router.matchRoutes(location.pathname, {
|
|
1781
|
+
strictParseParams: true
|
|
1782
|
+
});
|
|
1783
|
+
router.state = _extends({}, router.state, {
|
|
1784
|
+
pending: {
|
|
1785
|
+
matches: matches,
|
|
1786
|
+
location: router.location
|
|
1787
|
+
},
|
|
1788
|
+
status: 'loading'
|
|
1789
|
+
});
|
|
1790
|
+
router.notify(); // Load the matches
|
|
1791
|
+
|
|
1792
|
+
await router.loadMatches(matches, {
|
|
1793
|
+
withPending: true
|
|
1794
|
+
});
|
|
1795
|
+
|
|
1796
|
+
if (router.startedLoadingAt !== id) {
|
|
1797
|
+
// Ignore side-effects of match loading
|
|
1798
|
+
return router.navigationPromise;
|
|
1799
|
+
}
|
|
1800
|
+
|
|
1801
|
+
const previousMatches = router.state.matches;
|
|
1802
|
+
const exiting = [],
|
|
1803
|
+
staying = [];
|
|
1804
|
+
previousMatches.forEach(d => {
|
|
1805
|
+
if (matches.find(dd => dd.matchId === d.matchId)) {
|
|
1806
|
+
staying.push(d);
|
|
1807
|
+
} else {
|
|
1808
|
+
exiting.push(d);
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
const now = Date.now();
|
|
1812
|
+
exiting.forEach(d => {
|
|
1813
|
+
var _ref2, _d$options$loaderGcMa, _ref3, _d$options$loaderMaxA;
|
|
1814
|
+
|
|
1815
|
+
d.__.onExit == null ? void 0 : d.__.onExit({
|
|
1816
|
+
params: d.params,
|
|
1817
|
+
search: d.routeSearch
|
|
1818
|
+
}); // Clear idle error states when match leaves
|
|
1819
|
+
|
|
1820
|
+
if (d.status === 'error' && !d.isFetching) {
|
|
1821
|
+
d.status = 'idle';
|
|
1822
|
+
d.error = undefined;
|
|
1823
|
+
}
|
|
1824
|
+
|
|
1825
|
+
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);
|
|
1826
|
+
|
|
1827
|
+
if (gc > 0) {
|
|
1828
|
+
router.matchCache[d.matchId] = {
|
|
1829
|
+
gc: gc == Infinity ? Number.MAX_SAFE_INTEGER : now + gc,
|
|
1830
|
+
match: d
|
|
1831
|
+
};
|
|
1832
|
+
}
|
|
1833
|
+
});
|
|
1834
|
+
staying.forEach(d => {
|
|
1835
|
+
d.options.onTransition == null ? void 0 : d.options.onTransition({
|
|
1836
|
+
params: d.params,
|
|
1837
|
+
search: d.routeSearch
|
|
1838
|
+
});
|
|
1839
|
+
});
|
|
1840
|
+
const entering = matches.filter(d => {
|
|
1841
|
+
return !previousMatches.find(dd => dd.matchId === d.matchId);
|
|
1842
|
+
});
|
|
1843
|
+
entering.forEach(d => {
|
|
1844
|
+
d.__.onExit = d.options.onMatch == null ? void 0 : d.options.onMatch({
|
|
1845
|
+
params: d.params,
|
|
1846
|
+
search: d.search
|
|
1847
|
+
});
|
|
1848
|
+
delete router.matchCache[d.matchId];
|
|
1849
|
+
});
|
|
1850
|
+
|
|
1851
|
+
if (matches.some(d => d.status === 'loading')) {
|
|
1852
|
+
router.notify();
|
|
1853
|
+
await Promise.all(matches.map(d => d.__.loaderPromise || Promise.resolve()));
|
|
1854
|
+
}
|
|
1855
|
+
|
|
1856
|
+
if (router.startedLoadingAt !== id) {
|
|
1857
|
+
// Ignore side-effects of match loading
|
|
1858
|
+
return;
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
router.state = _extends({}, router.state, {
|
|
1862
|
+
location: router.location,
|
|
1863
|
+
matches,
|
|
1864
|
+
pending: undefined,
|
|
1865
|
+
status: 'idle'
|
|
1866
|
+
});
|
|
1867
|
+
router.notify();
|
|
1868
|
+
router.resolveNavigation();
|
|
1869
|
+
},
|
|
1870
|
+
cleanMatchCache: () => {
|
|
1871
|
+
const now = Date.now();
|
|
1872
|
+
Object.keys(router.matchCache).forEach(matchId => {
|
|
1873
|
+
const entry = router.matchCache[matchId]; // Don't remove loading matches
|
|
1874
|
+
|
|
1875
|
+
if (entry.match.status === 'loading') {
|
|
1876
|
+
return;
|
|
1877
|
+
} // Do not remove successful matches that are still valid
|
|
1878
|
+
|
|
1879
|
+
|
|
1880
|
+
if (entry.gc > 0 && entry.gc > now) {
|
|
1881
|
+
return;
|
|
1882
|
+
} // Everything else gets removed
|
|
1883
|
+
|
|
1884
|
+
|
|
1885
|
+
delete router.matchCache[matchId];
|
|
1886
|
+
});
|
|
1887
|
+
},
|
|
1888
|
+
loadRoute: async function loadRoute(navigateOpts) {
|
|
1889
|
+
if (navigateOpts === void 0) {
|
|
1890
|
+
navigateOpts = router.location;
|
|
1891
|
+
}
|
|
1892
|
+
|
|
1893
|
+
const next = router.buildNext(navigateOpts);
|
|
1894
|
+
const matches = router.matchRoutes(next.pathname, {
|
|
1895
|
+
strictParseParams: true
|
|
1896
|
+
});
|
|
1897
|
+
await router.loadMatches(matches);
|
|
1898
|
+
return matches;
|
|
1899
|
+
},
|
|
1900
|
+
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1901
|
+
var _ref4, _ref5, _loaderOpts$maxAge, _ref6, _ref7, _loaderOpts$gcMaxAge;
|
|
1902
|
+
|
|
1903
|
+
if (navigateOpts === void 0) {
|
|
1904
|
+
navigateOpts = router.location;
|
|
1905
|
+
}
|
|
1906
|
+
|
|
1907
|
+
const next = router.buildNext(navigateOpts);
|
|
1908
|
+
const matches = router.matchRoutes(next.pathname, {
|
|
1909
|
+
strictParseParams: true
|
|
1910
|
+
});
|
|
1911
|
+
await router.loadMatches(matches, {
|
|
1912
|
+
preload: true,
|
|
1913
|
+
maxAge: (_ref4 = (_ref5 = (_loaderOpts$maxAge = loaderOpts.maxAge) != null ? _loaderOpts$maxAge : router.options.defaultPreloadMaxAge) != null ? _ref5 : router.options.defaultLoaderMaxAge) != null ? _ref4 : 0,
|
|
1914
|
+
gcMaxAge: (_ref6 = (_ref7 = (_loaderOpts$gcMaxAge = loaderOpts.gcMaxAge) != null ? _loaderOpts$gcMaxAge : router.options.defaultPreloadGcMaxAge) != null ? _ref7 : router.options.defaultLoaderGcMaxAge) != null ? _ref6 : 0
|
|
1915
|
+
});
|
|
1916
|
+
return matches;
|
|
1917
|
+
},
|
|
1918
|
+
matchRoutes: (pathname, opts) => {
|
|
1919
|
+
var _router$state$pending3, _router$state$pending4;
|
|
1920
|
+
|
|
1921
|
+
router.cleanMatchCache();
|
|
1922
|
+
const matches = [];
|
|
1923
|
+
|
|
1924
|
+
if (!router.routeTree) {
|
|
1925
|
+
return matches;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
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 : [])];
|
|
1902
1929
|
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
delete routeMatch.__.pendingMinPromise;
|
|
1906
|
-
}
|
|
1907
|
-
} finally {
|
|
1908
|
-
if (id !== routeMatch.__.latestId) {
|
|
1909
|
-
return routeMatch.__.loaderPromise;
|
|
1910
|
-
}
|
|
1930
|
+
const recurse = async routes => {
|
|
1931
|
+
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1911
1932
|
|
|
1912
|
-
|
|
1933
|
+
const parentMatch = last(matches);
|
|
1934
|
+
let params = (_parentMatch$params = parentMatch == null ? void 0 : parentMatch.params) != null ? _parentMatch$params : {};
|
|
1935
|
+
const filteredRoutes = (_router$options$filte = router.options.filterRoutes == null ? void 0 : router.options.filterRoutes(routes)) != null ? _router$options$filte : routes;
|
|
1936
|
+
let foundRoutes = [];
|
|
1913
1937
|
|
|
1914
|
-
|
|
1915
|
-
|
|
1938
|
+
const findMatchInRoutes = (parentRoutes, routes) => {
|
|
1939
|
+
routes.some(route => {
|
|
1940
|
+
var _route$childRoutes, _route$childRoutes2, _route$options$caseSe;
|
|
1916
1941
|
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1942
|
+
if (!route.routePath && (_route$childRoutes = route.childRoutes) != null && _route$childRoutes.length) {
|
|
1943
|
+
return findMatchInRoutes([...foundRoutes, route], route.childRoutes);
|
|
1944
|
+
}
|
|
1920
1945
|
|
|
1921
|
-
|
|
1922
|
-
|
|
1946
|
+
const fuzzy = !!(route.routePath !== '/' || (_route$childRoutes2 = route.childRoutes) != null && _route$childRoutes2.length);
|
|
1947
|
+
const matchParams = matchPathname(pathname, {
|
|
1948
|
+
to: route.fullPath,
|
|
1949
|
+
fuzzy,
|
|
1950
|
+
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1951
|
+
});
|
|
1923
1952
|
|
|
1924
|
-
|
|
1925
|
-
|
|
1926
|
-
}
|
|
1953
|
+
if (matchParams) {
|
|
1954
|
+
let parsedParams;
|
|
1927
1955
|
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
return await routeMatch.__.loadPromise;
|
|
1931
|
-
}
|
|
1932
|
-
});
|
|
1956
|
+
try {
|
|
1957
|
+
var _route$options$parseP;
|
|
1933
1958
|
|
|
1934
|
-
|
|
1935
|
-
|
|
1959
|
+
parsedParams = (_route$options$parseP = route.options.parseParams == null ? void 0 : route.options.parseParams(matchParams)) != null ? _route$options$parseP : matchParams;
|
|
1960
|
+
} catch (err) {
|
|
1961
|
+
if (opts != null && opts.strictParseParams) {
|
|
1962
|
+
throw err;
|
|
1963
|
+
}
|
|
1964
|
+
}
|
|
1936
1965
|
|
|
1937
|
-
|
|
1938
|
-
|
|
1939
|
-
routeMatch.loaderData = replaceEqualDeep(routeMatch.loaderData, _extends$1({}, routeMatch.parentMatch.loaderData, routeMatch.routeLoaderData));
|
|
1940
|
-
}
|
|
1966
|
+
params = _extends({}, params, parsedParams);
|
|
1967
|
+
}
|
|
1941
1968
|
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
});
|
|
1946
|
-
}
|
|
1947
|
-
}
|
|
1969
|
+
if (!!matchParams) {
|
|
1970
|
+
foundRoutes = [...parentRoutes, route];
|
|
1971
|
+
}
|
|
1948
1972
|
|
|
1949
|
-
|
|
1950
|
-
|
|
1973
|
+
return !!foundRoutes.length;
|
|
1974
|
+
});
|
|
1975
|
+
return !!foundRoutes.length;
|
|
1976
|
+
};
|
|
1951
1977
|
|
|
1952
|
-
|
|
1953
|
-
return;
|
|
1954
|
-
} // if (matchLocation.search && !searchMatched) {
|
|
1955
|
-
// return
|
|
1956
|
-
// }
|
|
1978
|
+
findMatchInRoutes([], filteredRoutes);
|
|
1957
1979
|
|
|
1980
|
+
if (!foundRoutes.length) {
|
|
1981
|
+
return;
|
|
1982
|
+
}
|
|
1958
1983
|
|
|
1959
|
-
|
|
1960
|
-
|
|
1984
|
+
foundRoutes.forEach(foundRoute => {
|
|
1985
|
+
var _router$matchCache$ma;
|
|
1961
1986
|
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1987
|
+
const interpolatedPath = interpolatePath(foundRoute.routePath, params);
|
|
1988
|
+
const matchId = interpolatePath(foundRoute.routeId, params, true);
|
|
1989
|
+
const match = existingMatches.find(d => d.matchId === matchId) || ((_router$matchCache$ma = router.matchCache[matchId]) == null ? void 0 : _router$matchCache$ma.match) || createRouteMatch(router, foundRoute, {
|
|
1990
|
+
matchId,
|
|
1991
|
+
params,
|
|
1992
|
+
pathname: joinPaths([pathname, interpolatedPath])
|
|
1993
|
+
});
|
|
1994
|
+
matches.push(match);
|
|
1995
|
+
});
|
|
1996
|
+
const foundRoute = last(foundRoutes);
|
|
1968
1997
|
|
|
1969
|
-
|
|
1970
|
-
|
|
1998
|
+
if ((_foundRoute$childRout = foundRoute.childRoutes) != null && _foundRoute$childRout.length) {
|
|
1999
|
+
recurse(foundRoute.childRoutes);
|
|
2000
|
+
}
|
|
2001
|
+
};
|
|
1971
2002
|
|
|
1972
|
-
|
|
1973
|
-
|
|
2003
|
+
recurse([router.routeTree]);
|
|
2004
|
+
cascadeLoaderData(matches);
|
|
2005
|
+
return matches;
|
|
2006
|
+
},
|
|
2007
|
+
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
2008
|
+
const now = Date.now();
|
|
2009
|
+
const minMaxAge = loaderOpts != null && loaderOpts.preload ? Math.max(loaderOpts == null ? void 0 : loaderOpts.maxAge, loaderOpts == null ? void 0 : loaderOpts.gcMaxAge) : 0;
|
|
2010
|
+
const matchPromises = resolvedMatches.map(async match => {
|
|
2011
|
+
// Validate the match (loads search params etc)
|
|
2012
|
+
match.__.validate(); // If this is a preload, add it to the preload cache
|
|
1974
2013
|
|
|
1975
|
-
return segment.value;
|
|
1976
|
-
}));
|
|
1977
|
-
}
|
|
1978
2014
|
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
2015
|
+
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
2016
|
+
// If the match is currently active, don't preload it
|
|
2017
|
+
if (router.state.matches.find(d => d.matchId === match.matchId)) {
|
|
2018
|
+
return;
|
|
2019
|
+
}
|
|
1982
2020
|
|
|
1983
|
-
|
|
1984
|
-
|
|
1985
|
-
|
|
1986
|
-
|
|
2021
|
+
router.matchCache[match.matchId] = {
|
|
2022
|
+
gc: now + loaderOpts.gcMaxAge,
|
|
2023
|
+
match
|
|
2024
|
+
};
|
|
2025
|
+
} // If the match is invalid, errored or idle, trigger it to load
|
|
1987
2026
|
|
|
1988
|
-
return true;
|
|
1989
|
-
}
|
|
1990
2027
|
|
|
1991
|
-
|
|
1992
|
-
|
|
1993
|
-
|
|
2028
|
+
if (match.status === 'success' && match.getIsInvalid() || match.status === 'error' || match.status === 'idle') {
|
|
2029
|
+
const maxAge = loaderOpts != null && loaderOpts.preload ? loaderOpts == null ? void 0 : loaderOpts.maxAge : undefined;
|
|
2030
|
+
match.load({
|
|
2031
|
+
maxAge
|
|
2032
|
+
});
|
|
2033
|
+
}
|
|
1994
2034
|
|
|
1995
|
-
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
2035
|
+
if (match.status === 'loading') {
|
|
2036
|
+
// If requested, start the pending timers
|
|
2037
|
+
if (loaderOpts != null && loaderOpts.withPending) match.__.startPending(); // Wait for the first sign of activity from the match
|
|
2038
|
+
// This might be completion, error, or a pending state
|
|
1999
2039
|
|
|
2000
|
-
|
|
2001
|
-
|
|
2040
|
+
await match.__.loadPromise;
|
|
2041
|
+
}
|
|
2042
|
+
});
|
|
2043
|
+
router.notify();
|
|
2044
|
+
await Promise.all(matchPromises);
|
|
2045
|
+
},
|
|
2046
|
+
invalidateRoute: opts => {
|
|
2047
|
+
var _router$state$pending5, _router$state$pending6;
|
|
2002
2048
|
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2049
|
+
const next = router.buildNext(opts);
|
|
2050
|
+
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
2051
|
+
[...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 => {
|
|
2052
|
+
if (unloadedMatchIds.includes(match.matchId)) {
|
|
2053
|
+
match.invalidate();
|
|
2054
|
+
}
|
|
2055
|
+
});
|
|
2056
|
+
},
|
|
2057
|
+
reload: () => router.__.navigate({
|
|
2058
|
+
fromCurrent: true,
|
|
2059
|
+
replace: true,
|
|
2060
|
+
search: true
|
|
2061
|
+
}),
|
|
2062
|
+
resolvePath: (from, path) => {
|
|
2063
|
+
return resolvePath(router.basepath, from, cleanPath(path));
|
|
2064
|
+
},
|
|
2065
|
+
matchRoute: (location, opts) => {
|
|
2066
|
+
var _location$from;
|
|
2006
2067
|
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2068
|
+
// const location = router.buildNext(opts)
|
|
2069
|
+
location = _extends({}, location, {
|
|
2070
|
+
to: location.to ? router.resolvePath((_location$from = location.from) != null ? _location$from : '', location.to) : undefined
|
|
2071
|
+
});
|
|
2072
|
+
const next = router.buildNext(location);
|
|
2011
2073
|
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
}
|
|
2074
|
+
if (opts != null && opts.pending) {
|
|
2075
|
+
var _router$state$pending7;
|
|
2015
2076
|
|
|
2016
|
-
|
|
2017
|
-
|
|
2018
|
-
|
|
2077
|
+
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
2078
|
+
return false;
|
|
2079
|
+
}
|
|
2019
2080
|
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2081
|
+
return !!matchPathname(router.state.pending.location.pathname, _extends({}, opts, {
|
|
2082
|
+
to: next.pathname
|
|
2083
|
+
}));
|
|
2084
|
+
}
|
|
2023
2085
|
|
|
2024
|
-
|
|
2025
|
-
|
|
2086
|
+
return !!matchPathname(router.state.location.pathname, _extends({}, opts, {
|
|
2087
|
+
to: next.pathname
|
|
2088
|
+
}));
|
|
2089
|
+
},
|
|
2090
|
+
navigate: async _ref8 => {
|
|
2091
|
+
let {
|
|
2092
|
+
from,
|
|
2093
|
+
to = '.',
|
|
2094
|
+
search,
|
|
2095
|
+
hash,
|
|
2096
|
+
replace,
|
|
2097
|
+
params
|
|
2098
|
+
} = _ref8;
|
|
2099
|
+
// If this link simply reloads the current route,
|
|
2100
|
+
// make sure it has a new key so it will trigger a data refresh
|
|
2101
|
+
// If this `to` is a valid external URL, return
|
|
2102
|
+
// null for LinkUtils
|
|
2103
|
+
const toString = String(to);
|
|
2104
|
+
const fromString = String(from);
|
|
2105
|
+
let isExternal;
|
|
2026
2106
|
|
|
2027
|
-
|
|
2028
|
-
|
|
2029
|
-
|
|
2107
|
+
try {
|
|
2108
|
+
new URL("" + toString);
|
|
2109
|
+
isExternal = true;
|
|
2110
|
+
} catch (e) {}
|
|
2030
2111
|
|
|
2031
|
-
|
|
2032
|
-
|
|
2033
|
-
|
|
2034
|
-
|
|
2035
|
-
|
|
2036
|
-
|
|
2112
|
+
invariant(!isExternal, 'Attempting to navigate to external url with router.navigate!');
|
|
2113
|
+
return router.__.navigate({
|
|
2114
|
+
from: fromString,
|
|
2115
|
+
to: toString,
|
|
2116
|
+
search,
|
|
2117
|
+
hash,
|
|
2118
|
+
replace,
|
|
2119
|
+
params
|
|
2120
|
+
});
|
|
2121
|
+
},
|
|
2122
|
+
buildLink: _ref9 => {
|
|
2123
|
+
var _preload, _ref10;
|
|
2037
2124
|
|
|
2038
|
-
|
|
2039
|
-
|
|
2040
|
-
|
|
2041
|
-
|
|
2042
|
-
|
|
2043
|
-
|
|
2125
|
+
let {
|
|
2126
|
+
from,
|
|
2127
|
+
to = '.',
|
|
2128
|
+
search,
|
|
2129
|
+
params,
|
|
2130
|
+
hash,
|
|
2131
|
+
target,
|
|
2132
|
+
replace,
|
|
2133
|
+
activeOptions,
|
|
2134
|
+
preload,
|
|
2135
|
+
preloadMaxAge: userPreloadMaxAge,
|
|
2136
|
+
preloadGcMaxAge: userPreloadGcMaxAge,
|
|
2137
|
+
preloadDelay: userPreloadDelay,
|
|
2138
|
+
disabled
|
|
2139
|
+
} = _ref9;
|
|
2044
2140
|
|
|
2045
|
-
|
|
2046
|
-
|
|
2141
|
+
// If this link simply reloads the current route,
|
|
2142
|
+
// make sure it has a new key so it will trigger a data refresh
|
|
2143
|
+
// If this `to` is a valid external URL, return
|
|
2144
|
+
// null for LinkUtils
|
|
2145
|
+
try {
|
|
2146
|
+
new URL("" + to);
|
|
2147
|
+
return {
|
|
2148
|
+
type: 'external',
|
|
2149
|
+
href: to
|
|
2150
|
+
};
|
|
2151
|
+
} catch (e) {}
|
|
2047
2152
|
|
|
2048
|
-
|
|
2049
|
-
|
|
2050
|
-
|
|
2051
|
-
|
|
2153
|
+
const nextOpts = {
|
|
2154
|
+
from,
|
|
2155
|
+
to,
|
|
2156
|
+
search,
|
|
2157
|
+
params,
|
|
2158
|
+
hash,
|
|
2159
|
+
replace
|
|
2160
|
+
};
|
|
2161
|
+
const next = router.buildNext(nextOpts);
|
|
2162
|
+
preload = (_preload = preload) != null ? _preload : router.options.defaultPreload;
|
|
2163
|
+
const preloadDelay = (_ref10 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref10 : 0; // Compare path/hash for matches
|
|
2052
2164
|
|
|
2053
|
-
|
|
2054
|
-
|
|
2055
|
-
|
|
2056
|
-
|
|
2057
|
-
|
|
2058
|
-
|
|
2059
|
-
|
|
2060
|
-
|
|
2061
|
-
}
|
|
2062
|
-
}
|
|
2165
|
+
const pathIsEqual = router.state.location.pathname === next.pathname;
|
|
2166
|
+
const currentPathSplit = router.state.location.pathname.split('/');
|
|
2167
|
+
const nextPathSplit = next.pathname.split('/');
|
|
2168
|
+
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2169
|
+
const hashIsEqual = router.state.location.hash === next.hash; // Combine the matches based on user options
|
|
2170
|
+
|
|
2171
|
+
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
2172
|
+
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true; // The final "active" test
|
|
2063
2173
|
|
|
2064
|
-
|
|
2065
|
-
return false;
|
|
2066
|
-
}
|
|
2174
|
+
const isActive = pathTest && hashTest; // The click handler
|
|
2067
2175
|
|
|
2068
|
-
|
|
2069
|
-
|
|
2070
|
-
|
|
2071
|
-
}
|
|
2176
|
+
const handleClick = e => {
|
|
2177
|
+
if (!disabled && !isCtrlEvent(e) && !e.defaultPrevented && (!target || target === '_self') && e.button === 0) {
|
|
2178
|
+
e.preventDefault();
|
|
2072
2179
|
|
|
2073
|
-
if (!
|
|
2074
|
-
|
|
2075
|
-
}
|
|
2076
|
-
}
|
|
2077
|
-
}
|
|
2180
|
+
if (pathIsEqual && !search && !hash) {
|
|
2181
|
+
router.invalidateRoute(nextOpts);
|
|
2182
|
+
} // All is well? Navigate!)
|
|
2078
2183
|
|
|
2079
|
-
if (isLastRouteSegment && !isLastBaseSegment) {
|
|
2080
|
-
return !!matchLocation.fuzzy;
|
|
2081
|
-
}
|
|
2082
|
-
}
|
|
2083
2184
|
|
|
2084
|
-
|
|
2085
|
-
|
|
2185
|
+
router.__.navigate(nextOpts);
|
|
2186
|
+
}
|
|
2187
|
+
}; // The click handler
|
|
2086
2188
|
|
|
2087
|
-
return isMatch ? params : undefined;
|
|
2088
|
-
} // function matchBySearch(
|
|
2089
|
-
// search: SearchSchema,
|
|
2090
|
-
// matchLocation: MatchLocation,
|
|
2091
|
-
// ) {
|
|
2092
|
-
// return !!(matchLocation.search && matchLocation.search(search))
|
|
2093
|
-
// }
|
|
2094
2189
|
|
|
2095
|
-
|
|
2096
|
-
|
|
2097
|
-
|
|
2098
|
-
|
|
2190
|
+
const handleFocus = e => {
|
|
2191
|
+
if (preload) {
|
|
2192
|
+
router.preloadRoute(nextOpts, {
|
|
2193
|
+
maxAge: userPreloadMaxAge,
|
|
2194
|
+
gcMaxAge: userPreloadGcMaxAge
|
|
2195
|
+
});
|
|
2196
|
+
}
|
|
2197
|
+
};
|
|
2099
2198
|
|
|
2100
|
-
|
|
2101
|
-
|
|
2199
|
+
const handleEnter = e => {
|
|
2200
|
+
const target = e.target || {};
|
|
2102
2201
|
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
value: '/'
|
|
2108
|
-
});
|
|
2109
|
-
}
|
|
2202
|
+
if (preload) {
|
|
2203
|
+
if (target.preloadTimeout) {
|
|
2204
|
+
return;
|
|
2205
|
+
}
|
|
2110
2206
|
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2207
|
+
target.preloadTimeout = setTimeout(() => {
|
|
2208
|
+
target.preloadTimeout = null;
|
|
2209
|
+
router.preloadRoute(nextOpts, {
|
|
2210
|
+
maxAge: userPreloadMaxAge,
|
|
2211
|
+
gcMaxAge: userPreloadGcMaxAge
|
|
2212
|
+
});
|
|
2213
|
+
}, preloadDelay);
|
|
2214
|
+
}
|
|
2215
|
+
};
|
|
2114
2216
|
|
|
2217
|
+
const handleLeave = e => {
|
|
2218
|
+
const target = e.target || {};
|
|
2115
2219
|
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2120
|
-
type: 'wildcard',
|
|
2121
|
-
value: part
|
|
2220
|
+
if (target.preloadTimeout) {
|
|
2221
|
+
clearTimeout(target.preloadTimeout);
|
|
2222
|
+
target.preloadTimeout = null;
|
|
2223
|
+
}
|
|
2122
2224
|
};
|
|
2123
|
-
}
|
|
2124
2225
|
|
|
2125
|
-
if (part.charAt(0) === ':') {
|
|
2126
2226
|
return {
|
|
2127
|
-
type: '
|
|
2128
|
-
|
|
2227
|
+
type: 'internal',
|
|
2228
|
+
next,
|
|
2229
|
+
handleFocus,
|
|
2230
|
+
handleClick,
|
|
2231
|
+
handleEnter,
|
|
2232
|
+
handleLeave,
|
|
2233
|
+
isActive,
|
|
2234
|
+
disabled
|
|
2129
2235
|
};
|
|
2130
|
-
}
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
type: 'pathname',
|
|
2134
|
-
value: part
|
|
2135
|
-
};
|
|
2136
|
-
}));
|
|
2137
|
-
|
|
2138
|
-
if (pathname.slice(-1) === '/') {
|
|
2139
|
-
pathname = pathname.substring(1);
|
|
2140
|
-
segments.push({
|
|
2141
|
-
type: 'pathname',
|
|
2142
|
-
value: '/'
|
|
2143
|
-
});
|
|
2144
|
-
}
|
|
2236
|
+
},
|
|
2237
|
+
buildNext: opts => {
|
|
2238
|
+
const next = router.__.buildLocation(opts);
|
|
2145
2239
|
|
|
2146
|
-
|
|
2147
|
-
}
|
|
2240
|
+
const matches = router.matchRoutes(next.pathname);
|
|
2148
2241
|
|
|
2149
|
-
|
|
2150
|
-
|
|
2151
|
-
to = to.replace(new RegExp("^" + basepath), '/');
|
|
2152
|
-
let baseSegments = parsePathname(base);
|
|
2153
|
-
const toSegments = parsePathname(to);
|
|
2154
|
-
toSegments.forEach((toSegment, index) => {
|
|
2155
|
-
if (toSegment.value === '/') {
|
|
2156
|
-
if (!index) {
|
|
2157
|
-
// Leading slash
|
|
2158
|
-
baseSegments = [toSegment];
|
|
2159
|
-
} else if (index === toSegments.length - 1) {
|
|
2160
|
-
// Trailing Slash
|
|
2161
|
-
baseSegments.push(toSegment);
|
|
2162
|
-
} else ;
|
|
2163
|
-
} else if (toSegment.value === '..') {
|
|
2164
|
-
var _last2;
|
|
2242
|
+
const __preSearchFilters = matches.map(match => {
|
|
2243
|
+
var _match$options$preSea;
|
|
2165
2244
|
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
baseSegments.pop();
|
|
2169
|
-
}
|
|
2245
|
+
return (_match$options$preSea = match.options.preSearchFilters) != null ? _match$options$preSea : [];
|
|
2246
|
+
}).flat().filter(Boolean);
|
|
2170
2247
|
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
return;
|
|
2174
|
-
} else {
|
|
2175
|
-
baseSegments.push(toSegment);
|
|
2176
|
-
}
|
|
2177
|
-
});
|
|
2178
|
-
const joined = joinPaths([basepath, ...baseSegments.map(d => d.value)]);
|
|
2179
|
-
return cleanPath(joined);
|
|
2180
|
-
}
|
|
2181
|
-
function replaceEqualDeep(prev, next) {
|
|
2182
|
-
if (prev === next) {
|
|
2183
|
-
return prev;
|
|
2184
|
-
}
|
|
2248
|
+
const __postSearchFilters = matches.map(match => {
|
|
2249
|
+
var _match$options$postSe;
|
|
2185
2250
|
|
|
2186
|
-
|
|
2251
|
+
return (_match$options$postSe = match.options.postSearchFilters) != null ? _match$options$postSe : [];
|
|
2252
|
+
}).flat().filter(Boolean);
|
|
2187
2253
|
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2254
|
+
return router.__.buildLocation(_extends({}, opts, {
|
|
2255
|
+
__preSearchFilters,
|
|
2256
|
+
__postSearchFilters
|
|
2257
|
+
}));
|
|
2258
|
+
},
|
|
2259
|
+
__: {
|
|
2260
|
+
buildRouteTree: rootRouteConfig => {
|
|
2261
|
+
const recurseRoutes = (routeConfigs, parent) => {
|
|
2262
|
+
return routeConfigs.map(routeConfig => {
|
|
2263
|
+
const routeOptions = routeConfig.options;
|
|
2264
|
+
const route = createRoute(routeConfig, routeOptions, parent, router); // {
|
|
2265
|
+
// pendingMs: routeOptions.pendingMs ?? router.defaultPendingMs,
|
|
2266
|
+
// pendingMinMs: routeOptions.pendingMinMs ?? router.defaultPendingMinMs,
|
|
2267
|
+
// }
|
|
2268
|
+
|
|
2269
|
+
const existingRoute = router.routesById[route.routeId];
|
|
2270
|
+
|
|
2271
|
+
if (existingRoute) {
|
|
2272
|
+
{
|
|
2273
|
+
console.warn("Duplicate routes found with id: " + String(route.routeId), router.routesById, route);
|
|
2274
|
+
}
|
|
2194
2275
|
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2276
|
+
throw new Error();
|
|
2277
|
+
}
|
|
2278
|
+
router.routesById[route.routeId] = route;
|
|
2279
|
+
const children = routeConfig.children;
|
|
2280
|
+
route.childRoutes = children != null && children.length ? recurseRoutes(children, route) : undefined;
|
|
2281
|
+
return route;
|
|
2282
|
+
});
|
|
2283
|
+
};
|
|
2198
2284
|
|
|
2199
|
-
|
|
2200
|
-
|
|
2201
|
-
}
|
|
2202
|
-
|
|
2285
|
+
const routes = recurseRoutes([rootRouteConfig]);
|
|
2286
|
+
return routes[0];
|
|
2287
|
+
},
|
|
2288
|
+
parseLocation: (location, previousLocation) => {
|
|
2289
|
+
var _location$hash$split$;
|
|
2203
2290
|
|
|
2204
|
-
|
|
2205
|
-
|
|
2291
|
+
const parsedSearch = router.options.parseSearch(location.search);
|
|
2292
|
+
return {
|
|
2293
|
+
pathname: location.pathname,
|
|
2294
|
+
searchStr: location.search,
|
|
2295
|
+
search: replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.search, parsedSearch),
|
|
2296
|
+
hash: (_location$hash$split$ = location.hash.split('#').reverse()[0]) != null ? _location$hash$split$ : '',
|
|
2297
|
+
href: "" + location.pathname + location.search + location.hash,
|
|
2298
|
+
state: location.state,
|
|
2299
|
+
key: location.key
|
|
2300
|
+
};
|
|
2301
|
+
},
|
|
2302
|
+
navigate: location => {
|
|
2303
|
+
const next = router.buildNext(location);
|
|
2304
|
+
return router.__.commitLocation(next, location.replace);
|
|
2305
|
+
},
|
|
2306
|
+
buildLocation: function buildLocation(dest) {
|
|
2307
|
+
var _dest$from, _router$basepath, _dest$to, _last, _dest$params, _dest$__preSearchFilt, _functionalUpdate, _dest$__preSearchFilt2, _dest$__postSearchFil;
|
|
2206
2308
|
|
|
2207
|
-
|
|
2208
|
-
|
|
2309
|
+
if (dest === void 0) {
|
|
2310
|
+
dest = {};
|
|
2311
|
+
}
|
|
2209
2312
|
|
|
2210
|
-
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
} // If has modified constructor
|
|
2313
|
+
// const resolvedFrom: Location = {
|
|
2314
|
+
// ...router.location,
|
|
2315
|
+
const fromPathname = dest.fromCurrent ? router.location.pathname : (_dest$from = dest.from) != null ? _dest$from : router.location.pathname;
|
|
2214
2316
|
|
|
2317
|
+
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2215
2318
|
|
|
2216
|
-
|
|
2319
|
+
const fromMatches = router.matchRoutes(router.location.pathname, {
|
|
2320
|
+
strictParseParams: true
|
|
2321
|
+
});
|
|
2322
|
+
const toMatches = router.matchRoutes(pathname);
|
|
2217
2323
|
|
|
2218
|
-
|
|
2219
|
-
return true;
|
|
2220
|
-
} // If has modified prototype
|
|
2324
|
+
const prevParams = _extends({}, (_last = last(fromMatches)) == null ? void 0 : _last.params);
|
|
2221
2325
|
|
|
2326
|
+
let nextParams = ((_dest$params = dest.params) != null ? _dest$params : true) === true ? prevParams : functionalUpdate(dest.params, prevParams);
|
|
2222
2327
|
|
|
2223
|
-
|
|
2328
|
+
if (nextParams) {
|
|
2329
|
+
toMatches.map(d => d.options.stringifyParams).filter(Boolean).forEach(fn => {
|
|
2330
|
+
Object.assign({}, nextParams, fn(nextParams));
|
|
2331
|
+
});
|
|
2332
|
+
}
|
|
2224
2333
|
|
|
2225
|
-
|
|
2226
|
-
return false;
|
|
2227
|
-
} // If constructor does not have an Object-specific method
|
|
2334
|
+
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {}); // Pre filters first
|
|
2228
2335
|
|
|
2336
|
+
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
|
|
2229
2337
|
|
|
2230
|
-
|
|
2231
|
-
|
|
2232
|
-
|
|
2338
|
+
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
2339
|
+
: dest.search ? (_functionalUpdate = functionalUpdate(dest.search, preFilteredSearch)) != null ? _functionalUpdate : {} // Updater
|
|
2340
|
+
: (_dest$__preSearchFilt2 = dest.__preSearchFilters) != null && _dest$__preSearchFilt2.length ? preFilteredSearch // Preserve resolvedFrom filters
|
|
2341
|
+
: {}; // Then post filters
|
|
2233
2342
|
|
|
2343
|
+
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2344
|
+
const search = replaceEqualDeep(router.location.search, postFilteredSearch);
|
|
2345
|
+
const searchStr = router.options.stringifySearch(search);
|
|
2346
|
+
let hash = dest.hash === true ? router.location.hash : functionalUpdate(dest.hash, router.location.hash);
|
|
2347
|
+
hash = hash ? "#" + hash : '';
|
|
2348
|
+
return {
|
|
2349
|
+
pathname,
|
|
2350
|
+
search,
|
|
2351
|
+
searchStr,
|
|
2352
|
+
state: router.location.state,
|
|
2353
|
+
hash,
|
|
2354
|
+
href: "" + pathname + searchStr + hash,
|
|
2355
|
+
key: dest.key
|
|
2356
|
+
};
|
|
2357
|
+
},
|
|
2358
|
+
commitLocation: (next, replace) => {
|
|
2359
|
+
const id = '' + Date.now() + Math.random();
|
|
2360
|
+
if (router.navigateTimeout) clearTimeout(router.navigateTimeout);
|
|
2361
|
+
let nextAction = 'replace';
|
|
2234
2362
|
|
|
2235
|
-
|
|
2236
|
-
|
|
2363
|
+
if (!replace) {
|
|
2364
|
+
nextAction = 'push';
|
|
2365
|
+
}
|
|
2237
2366
|
|
|
2238
|
-
|
|
2239
|
-
return Object.prototype.toString.call(o) === '[object Object]';
|
|
2240
|
-
}
|
|
2367
|
+
const isSameUrl = router.__.parseLocation(history.location).href === next.href;
|
|
2241
2368
|
|
|
2242
|
-
|
|
2243
|
-
|
|
2244
|
-
|
|
2245
|
-
return searchStr => {
|
|
2246
|
-
if (searchStr.substring(0, 1) === '?') {
|
|
2247
|
-
searchStr = searchStr.substring(1);
|
|
2248
|
-
}
|
|
2369
|
+
if (isSameUrl && !next.key) {
|
|
2370
|
+
nextAction = 'replace';
|
|
2371
|
+
}
|
|
2249
2372
|
|
|
2250
|
-
|
|
2373
|
+
if (nextAction === 'replace') {
|
|
2374
|
+
history.replace({
|
|
2375
|
+
pathname: next.pathname,
|
|
2376
|
+
hash: next.hash,
|
|
2377
|
+
search: next.searchStr
|
|
2378
|
+
}, {
|
|
2379
|
+
id
|
|
2380
|
+
});
|
|
2381
|
+
} else {
|
|
2382
|
+
history.push({
|
|
2383
|
+
pathname: next.pathname,
|
|
2384
|
+
hash: next.hash,
|
|
2385
|
+
search: next.searchStr
|
|
2386
|
+
}, {
|
|
2387
|
+
id
|
|
2388
|
+
});
|
|
2389
|
+
}
|
|
2251
2390
|
|
|
2252
|
-
|
|
2253
|
-
|
|
2391
|
+
router.navigationPromise = new Promise(resolve => {
|
|
2392
|
+
const previousNavigationResolve = router.resolveNavigation;
|
|
2254
2393
|
|
|
2255
|
-
|
|
2256
|
-
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
}
|
|
2394
|
+
router.resolveNavigation = () => {
|
|
2395
|
+
previousNavigationResolve();
|
|
2396
|
+
resolve();
|
|
2397
|
+
};
|
|
2398
|
+
});
|
|
2399
|
+
return router.navigationPromise;
|
|
2260
2400
|
}
|
|
2261
2401
|
}
|
|
2262
|
-
|
|
2263
|
-
return query;
|
|
2264
2402
|
};
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
|
|
2268
|
-
search = _extends$1({}, search);
|
|
2269
|
-
|
|
2270
|
-
if (search) {
|
|
2271
|
-
Object.keys(search).forEach(key => {
|
|
2272
|
-
const val = search[key];
|
|
2273
|
-
|
|
2274
|
-
if (typeof val === 'undefined' || val === undefined) {
|
|
2275
|
-
delete search[key];
|
|
2276
|
-
} else if (val && typeof val === 'object' && val !== null) {
|
|
2277
|
-
try {
|
|
2278
|
-
search[key] = stringify(val);
|
|
2279
|
-
} catch (err) {// silent
|
|
2280
|
-
}
|
|
2281
|
-
}
|
|
2282
|
-
});
|
|
2283
|
-
}
|
|
2403
|
+
router.location = router.__.parseLocation(history.location);
|
|
2404
|
+
router.state.location = router.location;
|
|
2405
|
+
router.update(userOptions); // Allow frameworks to hook into the router creation
|
|
2284
2406
|
|
|
2285
|
-
|
|
2286
|
-
|
|
2287
|
-
};
|
|
2407
|
+
router.options.createRouter == null ? void 0 : router.options.createRouter(router);
|
|
2408
|
+
return router;
|
|
2288
2409
|
}
|
|
2289
2410
|
|
|
2290
2411
|
function isCtrlEvent(e) {
|
|
2291
2412
|
return !!(e.metaKey || e.altKey || e.ctrlKey || e.shiftKey);
|
|
2292
2413
|
}
|
|
2293
2414
|
|
|
2294
|
-
|
|
2295
|
-
|
|
2296
|
-
}
|
|
2297
|
-
|
|
2415
|
+
exports.cascadeLoaderData = cascadeLoaderData;
|
|
2416
|
+
exports.cleanPath = cleanPath;
|
|
2298
2417
|
exports.createBrowserHistory = createBrowserHistory;
|
|
2299
2418
|
exports.createHashHistory = createHashHistory;
|
|
2300
2419
|
exports.createMemoryHistory = createMemoryHistory;
|
|
@@ -2302,18 +2421,26 @@
|
|
|
2302
2421
|
exports.createRouteConfig = createRouteConfig;
|
|
2303
2422
|
exports.createRouteMatch = createRouteMatch;
|
|
2304
2423
|
exports.createRouter = createRouter;
|
|
2424
|
+
exports.decode = decode;
|
|
2305
2425
|
exports.defaultParseSearch = defaultParseSearch;
|
|
2306
2426
|
exports.defaultStringifySearch = defaultStringifySearch;
|
|
2427
|
+
exports.encode = encode;
|
|
2307
2428
|
exports.functionalUpdate = functionalUpdate;
|
|
2429
|
+
exports.interpolatePath = interpolatePath;
|
|
2430
|
+
exports.invariant = invariant;
|
|
2431
|
+
exports.joinPaths = joinPaths;
|
|
2308
2432
|
exports.last = last;
|
|
2309
2433
|
exports.matchByPath = matchByPath;
|
|
2310
2434
|
exports.matchPathname = matchPathname;
|
|
2311
2435
|
exports.parsePathname = parsePathname;
|
|
2312
2436
|
exports.parseSearchWith = parseSearchWith;
|
|
2313
2437
|
exports.replaceEqualDeep = replaceEqualDeep;
|
|
2314
|
-
exports.resolvePath =
|
|
2438
|
+
exports.resolvePath = resolvePath;
|
|
2315
2439
|
exports.rootRouteId = rootRouteId;
|
|
2316
2440
|
exports.stringifySearchWith = stringifySearchWith;
|
|
2441
|
+
exports.trimPath = trimPath;
|
|
2442
|
+
exports.trimPathLeft = trimPathLeft;
|
|
2443
|
+
exports.trimPathRight = trimPathRight;
|
|
2317
2444
|
exports.warning = warning;
|
|
2318
2445
|
|
|
2319
2446
|
Object.defineProperty(exports, '__esModule', { value: true });
|