@tanstack/router-core 0.0.1-beta.34 → 0.0.1-beta.36
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/path.js +2 -2
- package/build/cjs/path.js.map +1 -1
- package/build/cjs/route.js +0 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/routeConfig.js.map +1 -1
- package/build/cjs/routeMatch.js +2 -2
- package/build/cjs/routeMatch.js.map +1 -1
- package/build/cjs/router.js +93 -83
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +97 -88
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +136 -136
- package/build/types/index.d.ts +9 -12
- package/build/umd/index.development.js +97 -88
- 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 +1 -1
- package/src/path.ts +2 -2
- package/src/route.ts +0 -1
- package/src/routeConfig.ts +7 -2
- package/src/routeMatch.ts +4 -2
- package/src/router.ts +151 -114
package/build/types/index.d.ts
CHANGED
|
@@ -154,19 +154,17 @@ interface LoaderState<TFullSearchSchema extends AnySearchSchema = {}, TAllParams
|
|
|
154
154
|
}
|
|
155
155
|
interface RouterState<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
|
|
156
156
|
status: 'idle' | 'loading';
|
|
157
|
-
|
|
158
|
-
|
|
157
|
+
latestLocation: Location<TSearchObj, TState>;
|
|
158
|
+
currentMatches: RouteMatch[];
|
|
159
|
+
currentLocation: Location<TSearchObj, TState>;
|
|
160
|
+
pendingMatches?: RouteMatch[];
|
|
161
|
+
pendingLocation?: Location<TSearchObj, TState>;
|
|
159
162
|
lastUpdated: number;
|
|
160
163
|
actions: Record<string, Action>;
|
|
161
164
|
loaders: Record<string, Loader>;
|
|
162
|
-
pending?: PendingState;
|
|
163
165
|
isFetching: boolean;
|
|
164
166
|
isPreloading: boolean;
|
|
165
167
|
}
|
|
166
|
-
interface PendingState {
|
|
167
|
-
location: Location;
|
|
168
|
-
matches: RouteMatch[];
|
|
169
|
-
}
|
|
170
168
|
type Listener = (router: Router<any, any, any>) => void;
|
|
171
169
|
type ListenerFn = () => void;
|
|
172
170
|
interface BuildNextOptions {
|
|
@@ -197,11 +195,10 @@ interface MatchRouteOptions {
|
|
|
197
195
|
caseSensitive?: boolean;
|
|
198
196
|
fuzzy?: boolean;
|
|
199
197
|
}
|
|
200
|
-
interface DehydratedRouterState extends Pick<RouterState, 'status' | '
|
|
201
|
-
|
|
198
|
+
interface DehydratedRouterState extends Pick<RouterState, 'status' | 'latestLocation' | 'currentLocation' | 'lastUpdated'> {
|
|
199
|
+
currentMatches: DehydratedRouteMatch[];
|
|
202
200
|
}
|
|
203
201
|
interface DehydratedRouter<TRouterContext = unknown> {
|
|
204
|
-
location: Router['__location'];
|
|
205
202
|
state: DehydratedRouterState;
|
|
206
203
|
context: TRouterContext;
|
|
207
204
|
}
|
|
@@ -218,7 +215,6 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
218
215
|
options: PickAsRequired<RouterOptions<TRouteConfig, TRouterContext>, 'stringifySearch' | 'parseSearch' | 'context'>;
|
|
219
216
|
basepath: string;
|
|
220
217
|
listeners: Listener[];
|
|
221
|
-
__location: Location<TAllRouteInfo['fullSearchSchema']>;
|
|
222
218
|
navigateTimeout?: Timeout;
|
|
223
219
|
nextAction?: 'push' | 'replace';
|
|
224
220
|
state: RouterState<TAllRouteInfo['fullSearchSchema']>;
|
|
@@ -381,6 +377,7 @@ type RouteOptions<TRouteId extends string = string, TPath extends string = strin
|
|
|
381
377
|
router: Router<any, any, unknown>;
|
|
382
378
|
match: RouteMatch;
|
|
383
379
|
}) => Promise<void> | void;
|
|
380
|
+
onLoadError?: (err: any) => void;
|
|
384
381
|
onLoaded?: (matchContext: {
|
|
385
382
|
params: TAllParams;
|
|
386
383
|
search: TFullSearchSchema;
|
|
@@ -630,4 +627,4 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
|
630
627
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
631
628
|
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
632
629
|
|
|
633
|
-
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, DehydratedRouter, DehydratedRouterState, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, Location, LocationState, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, PathParamMask,
|
|
630
|
+
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, DehydratedRouter, DehydratedRouterState, Expand, FilterRoutesFn, FrameworkGenerics, FromLocation, GetFrameworkGeneric, IsAny, IsAnyBoolean, IsKnown, LinkInfo, LinkOptions, ListenerFn, Loader, LoaderContext, LoaderFn, LoaderState, Location, LocationState, MatchCacheEntry, MatchLocation, MatchRouteOptions, NavigateOptionsAbsolute, NoInfer, ParentParams, ParsePathParams, ParseRouteConfig, PathParamMask, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RegisterRouter, RegisteredAllRouteInfo, RegisteredRouter, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMeta, RouteOptions, Router, RouterContext, RouterOptions, RouterState, RoutesById, RoutesInfoInner, SearchFilter, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Timeout, ToIdOption, ToOptions, ToPathOption, UnionToIntersection, UnloaderFn, Updater, ValidFromPath, ValueKeys, Values, cleanPath, createRoute, createRouteConfig, createRouteMatch, createRouter, decode, defaultParseSearch, defaultStringifySearch, encode, functionalUpdate, interpolatePath, joinPaths, last, matchByPath, matchPathname, parsePathname, parseSearchWith, pick, replaceEqualDeep, resolvePath, rootRouteId, stringifySearchWith, trimPath, trimPathLeft, trimPathRight, warning };
|
|
@@ -1031,10 +1031,10 @@
|
|
|
1031
1031
|
}
|
|
1032
1032
|
function matchByPath(basepath, from, matchLocation) {
|
|
1033
1033
|
var _matchLocation$to;
|
|
1034
|
-
if (
|
|
1034
|
+
if (!from.startsWith(basepath)) {
|
|
1035
1035
|
return undefined;
|
|
1036
1036
|
}
|
|
1037
|
-
from =
|
|
1037
|
+
from = basepath != '/' ? from.substring(basepath.length) : from;
|
|
1038
1038
|
const baseSegments = parsePathname(from);
|
|
1039
1039
|
const to = "" + ((_matchLocation$to = matchLocation.to) != null ? _matchLocation$to : '*');
|
|
1040
1040
|
const routeSegments = parsePathname(to);
|
|
@@ -1194,7 +1194,6 @@
|
|
|
1194
1194
|
actionState.status = 'success';
|
|
1195
1195
|
return res;
|
|
1196
1196
|
} catch (err) {
|
|
1197
|
-
console.log('tanner');
|
|
1198
1197
|
console.error(err);
|
|
1199
1198
|
actionState.error = err;
|
|
1200
1199
|
actionState.status = 'error';
|
|
@@ -1348,7 +1347,7 @@
|
|
|
1348
1347
|
validate: () => {
|
|
1349
1348
|
var _routeMatch$parentMat, _routeMatch$parentMat2;
|
|
1350
1349
|
// Validate the search params and stabilize them
|
|
1351
|
-
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.
|
|
1350
|
+
const parentSearch = (_routeMatch$parentMat = (_routeMatch$parentMat2 = routeMatch.parentMatch) == null ? void 0 : _routeMatch$parentMat2.search) != null ? _routeMatch$parentMat : router.state.currentLocation.search;
|
|
1352
1351
|
try {
|
|
1353
1352
|
var _validator;
|
|
1354
1353
|
const prevSearch = routeMatch.routeSearch;
|
|
@@ -1400,7 +1399,7 @@
|
|
|
1400
1399
|
// If this is a preload, add it to the preload cache
|
|
1401
1400
|
if (loaderOpts != null && loaderOpts.preload && minMaxAge > 0) {
|
|
1402
1401
|
// If the match is currently active, don't preload it
|
|
1403
|
-
if (router.state.
|
|
1402
|
+
if (router.state.currentMatches.find(d => d.matchId === routeMatch.matchId)) {
|
|
1404
1403
|
return;
|
|
1405
1404
|
}
|
|
1406
1405
|
router.matchCache[routeMatch.matchId] = {
|
|
@@ -1554,8 +1553,9 @@
|
|
|
1554
1553
|
function getInitialRouterState() {
|
|
1555
1554
|
return {
|
|
1556
1555
|
status: 'idle',
|
|
1557
|
-
|
|
1558
|
-
|
|
1556
|
+
latestLocation: null,
|
|
1557
|
+
currentLocation: null,
|
|
1558
|
+
currentMatches: [],
|
|
1559
1559
|
actions: {},
|
|
1560
1560
|
loaders: {},
|
|
1561
1561
|
lastUpdated: Date.now(),
|
|
@@ -1586,7 +1586,6 @@
|
|
|
1586
1586
|
basepath: '',
|
|
1587
1587
|
routeTree: undefined,
|
|
1588
1588
|
routesById: {},
|
|
1589
|
-
__location: undefined,
|
|
1590
1589
|
//
|
|
1591
1590
|
resolveNavigation: () => {},
|
|
1592
1591
|
matchCache: {},
|
|
@@ -1606,65 +1605,53 @@
|
|
|
1606
1605
|
return router.routesById[id];
|
|
1607
1606
|
},
|
|
1608
1607
|
notify: () => {
|
|
1609
|
-
const isFetching = router.state.status === 'loading' || router.state.
|
|
1610
|
-
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.
|
|
1608
|
+
const isFetching = router.state.status === 'loading' || router.state.currentMatches.some(d => d.isFetching);
|
|
1609
|
+
const isPreloading = Object.values(router.matchCache).some(d => d.match.isFetching && !router.state.currentMatches.find(dd => dd.matchId === d.match.matchId));
|
|
1611
1610
|
if (router.state.isFetching !== isFetching || router.state.isPreloading !== isPreloading) {
|
|
1612
1611
|
router.state = _extends({}, router.state, {
|
|
1613
1612
|
isFetching,
|
|
1614
1613
|
isPreloading
|
|
1615
1614
|
});
|
|
1616
1615
|
}
|
|
1617
|
-
cascadeLoaderData(router.state.
|
|
1616
|
+
cascadeLoaderData(router.state.currentMatches);
|
|
1618
1617
|
router.listeners.forEach(listener => listener(router));
|
|
1619
1618
|
},
|
|
1620
1619
|
dehydrate: () => {
|
|
1621
1620
|
return {
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
matches: router.state.matches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1621
|
+
state: _extends({}, pick(router.state, ['latestLocation', 'currentLocation', 'status', 'lastUpdated']), {
|
|
1622
|
+
currentMatches: router.state.currentMatches.map(match => pick(match, ['matchId', 'status', 'routeLoaderData', 'loaderData', 'isInvalid', 'invalidAt']))
|
|
1625
1623
|
}),
|
|
1626
1624
|
context: router.options.context
|
|
1627
1625
|
};
|
|
1628
1626
|
},
|
|
1629
1627
|
hydrate: dehydratedState => {
|
|
1630
1628
|
// Update the location
|
|
1631
|
-
router.
|
|
1629
|
+
router.state.latestLocation = dehydratedState.state.latestLocation;
|
|
1630
|
+
router.state.currentLocation = dehydratedState.state.currentLocation;
|
|
1632
1631
|
|
|
1633
1632
|
// Update the context
|
|
1634
1633
|
router.options.context = dehydratedState.context;
|
|
1635
1634
|
|
|
1636
1635
|
// Match the routes
|
|
1637
|
-
const
|
|
1636
|
+
const currentMatches = router.matchRoutes(router.state.latestLocation.pathname, {
|
|
1638
1637
|
strictParseParams: true
|
|
1639
1638
|
});
|
|
1640
|
-
|
|
1641
|
-
const dehydratedMatch = dehydratedState.state.
|
|
1639
|
+
currentMatches.forEach((match, index) => {
|
|
1640
|
+
const dehydratedMatch = dehydratedState.state.currentMatches[index];
|
|
1642
1641
|
invariant(dehydratedMatch, 'Oh no! Dehydrated route matches did not match the active state of the router 😬');
|
|
1643
1642
|
Object.assign(match, dehydratedMatch);
|
|
1644
1643
|
});
|
|
1645
|
-
|
|
1644
|
+
currentMatches.forEach(match => match.__.validate());
|
|
1646
1645
|
router.state = _extends({}, router.state, dehydratedState, {
|
|
1647
|
-
|
|
1646
|
+
currentMatches
|
|
1648
1647
|
});
|
|
1649
1648
|
},
|
|
1650
1649
|
mount: () => {
|
|
1651
|
-
router.
|
|
1652
|
-
to: '.',
|
|
1653
|
-
search: true,
|
|
1654
|
-
hash: true
|
|
1655
|
-
});
|
|
1656
|
-
|
|
1657
|
-
// If the current location isn't updated, trigger a navigation
|
|
1658
|
-
// to the current location. Otherwise, load the current location.
|
|
1659
|
-
// if (next.href !== router.__location.href) {
|
|
1660
|
-
// router.__.commitLocation(next, true)
|
|
1661
|
-
// }
|
|
1662
|
-
|
|
1663
|
-
if (!router.state.matches.length) {
|
|
1650
|
+
if (!router.state.currentMatches.length) {
|
|
1664
1651
|
router.load();
|
|
1665
1652
|
}
|
|
1666
1653
|
const unsub = router.history.listen(event => {
|
|
1667
|
-
router.load(router.__.parseLocation(event.location, router.
|
|
1654
|
+
router.load(router.__.parseLocation(event.location, router.state.latestLocation));
|
|
1668
1655
|
});
|
|
1669
1656
|
|
|
1670
1657
|
// addEventListener does not exist in React Native, but window does
|
|
@@ -1689,12 +1676,12 @@
|
|
|
1689
1676
|
update: opts => {
|
|
1690
1677
|
var _trimPath;
|
|
1691
1678
|
const newHistory = (opts == null ? void 0 : opts.history) !== router.history;
|
|
1692
|
-
if (!router.
|
|
1679
|
+
if (!router.state.latestLocation || newHistory) {
|
|
1693
1680
|
if (opts != null && opts.history) {
|
|
1694
1681
|
router.history = opts.history;
|
|
1695
1682
|
}
|
|
1696
|
-
router.
|
|
1697
|
-
router.state.
|
|
1683
|
+
router.state.latestLocation = router.__.parseLocation(router.history.location);
|
|
1684
|
+
router.state.currentLocation = router.state.latestLocation;
|
|
1698
1685
|
}
|
|
1699
1686
|
Object.assign(router.options, opts);
|
|
1700
1687
|
const {
|
|
@@ -1709,8 +1696,8 @@
|
|
|
1709
1696
|
return router;
|
|
1710
1697
|
},
|
|
1711
1698
|
cancelMatches: () => {
|
|
1712
|
-
var _router$state$pending
|
|
1713
|
-
[...router.state.
|
|
1699
|
+
var _router$state$pending;
|
|
1700
|
+
[...router.state.currentMatches, ...((_router$state$pending = router.state.pendingMatches) != null ? _router$state$pending : [])].forEach(match => {
|
|
1714
1701
|
match.cancel();
|
|
1715
1702
|
});
|
|
1716
1703
|
},
|
|
@@ -1719,53 +1706,43 @@
|
|
|
1719
1706
|
router.startedLoadingAt = id;
|
|
1720
1707
|
if (next) {
|
|
1721
1708
|
// Ingest the new location
|
|
1722
|
-
router.
|
|
1709
|
+
router.state.latestLocation = next;
|
|
1723
1710
|
}
|
|
1724
1711
|
|
|
1725
1712
|
// Cancel any pending matches
|
|
1726
1713
|
router.cancelMatches();
|
|
1727
1714
|
|
|
1728
1715
|
// Match the routes
|
|
1729
|
-
const matches = router.matchRoutes(router.
|
|
1716
|
+
const matches = router.matchRoutes(router.state.latestLocation.pathname, {
|
|
1730
1717
|
strictParseParams: true
|
|
1731
1718
|
});
|
|
1732
1719
|
if (typeof document !== 'undefined') {
|
|
1733
1720
|
router.state = _extends({}, router.state, {
|
|
1734
|
-
|
|
1735
|
-
|
|
1736
|
-
|
|
1737
|
-
},
|
|
1738
|
-
status: 'loading'
|
|
1721
|
+
status: 'loading',
|
|
1722
|
+
pendingMatches: matches,
|
|
1723
|
+
pendingLocation: router.state.latestLocation
|
|
1739
1724
|
});
|
|
1740
1725
|
} else {
|
|
1741
1726
|
router.state = _extends({}, router.state, {
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1727
|
+
status: 'loading',
|
|
1728
|
+
currentMatches: matches,
|
|
1729
|
+
currentLocation: router.state.latestLocation
|
|
1745
1730
|
});
|
|
1746
1731
|
}
|
|
1732
|
+
router.notify();
|
|
1747
1733
|
|
|
1748
|
-
//
|
|
1734
|
+
// Load the matches
|
|
1749
1735
|
try {
|
|
1750
|
-
await
|
|
1751
|
-
router: router,
|
|
1752
|
-
match
|
|
1753
|
-
})));
|
|
1736
|
+
await router.loadMatches(matches);
|
|
1754
1737
|
} catch (err) {
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
}
|
|
1758
|
-
throw err;
|
|
1738
|
+
console.log(err);
|
|
1739
|
+
invariant(false, 'Matches failed to load due to error above ☝️. Navigation cancelled!');
|
|
1759
1740
|
}
|
|
1760
|
-
router.notify();
|
|
1761
|
-
|
|
1762
|
-
// Load the matches
|
|
1763
|
-
await router.loadMatches(matches);
|
|
1764
1741
|
if (router.startedLoadingAt !== id) {
|
|
1765
1742
|
// Ignore side-effects of match loading
|
|
1766
1743
|
return router.navigationPromise;
|
|
1767
1744
|
}
|
|
1768
|
-
const previousMatches = router.state.
|
|
1745
|
+
const previousMatches = router.state.currentMatches;
|
|
1769
1746
|
const exiting = [],
|
|
1770
1747
|
staying = [];
|
|
1771
1748
|
previousMatches.forEach(d => {
|
|
@@ -1824,10 +1801,11 @@
|
|
|
1824
1801
|
}
|
|
1825
1802
|
});
|
|
1826
1803
|
router.state = _extends({}, router.state, {
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
|
|
1830
|
-
|
|
1804
|
+
status: 'idle',
|
|
1805
|
+
currentLocation: router.state.latestLocation,
|
|
1806
|
+
currentMatches: matches,
|
|
1807
|
+
pendingLocation: undefined,
|
|
1808
|
+
pendingMatches: undefined
|
|
1831
1809
|
});
|
|
1832
1810
|
router.notify();
|
|
1833
1811
|
router.resolveNavigation();
|
|
@@ -1853,7 +1831,7 @@
|
|
|
1853
1831
|
},
|
|
1854
1832
|
loadRoute: async function loadRoute(navigateOpts) {
|
|
1855
1833
|
if (navigateOpts === void 0) {
|
|
1856
|
-
navigateOpts = router.
|
|
1834
|
+
navigateOpts = router.state.latestLocation;
|
|
1857
1835
|
}
|
|
1858
1836
|
const next = router.buildNext(navigateOpts);
|
|
1859
1837
|
const matches = router.matchRoutes(next.pathname, {
|
|
@@ -1865,7 +1843,7 @@
|
|
|
1865
1843
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1866
1844
|
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
1867
1845
|
if (navigateOpts === void 0) {
|
|
1868
|
-
navigateOpts = router.
|
|
1846
|
+
navigateOpts = router.state.latestLocation;
|
|
1869
1847
|
}
|
|
1870
1848
|
const next = router.buildNext(navigateOpts);
|
|
1871
1849
|
const matches = router.matchRoutes(next.pathname, {
|
|
@@ -1879,13 +1857,13 @@
|
|
|
1879
1857
|
return matches;
|
|
1880
1858
|
},
|
|
1881
1859
|
matchRoutes: (pathname, opts) => {
|
|
1882
|
-
var _router$state$
|
|
1860
|
+
var _router$state$pending2;
|
|
1883
1861
|
router.cleanMatchCache();
|
|
1884
1862
|
const matches = [];
|
|
1885
1863
|
if (!router.routeTree) {
|
|
1886
1864
|
return matches;
|
|
1887
1865
|
}
|
|
1888
|
-
const existingMatches = [...router.state.
|
|
1866
|
+
const existingMatches = [...router.state.currentMatches, ...((_router$state$pending2 = router.state.pendingMatches) != null ? _router$state$pending2 : [])];
|
|
1889
1867
|
const recurse = async routes => {
|
|
1890
1868
|
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1891
1869
|
const parentMatch = last(matches);
|
|
@@ -1904,6 +1882,15 @@
|
|
|
1904
1882
|
fuzzy,
|
|
1905
1883
|
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1906
1884
|
});
|
|
1885
|
+
|
|
1886
|
+
// console.log(
|
|
1887
|
+
// router.basepath,
|
|
1888
|
+
// route.fullPath,
|
|
1889
|
+
// fuzzy,
|
|
1890
|
+
// pathname,
|
|
1891
|
+
// matchParams,
|
|
1892
|
+
// )
|
|
1893
|
+
|
|
1907
1894
|
if (matchParams) {
|
|
1908
1895
|
let parsedParams;
|
|
1909
1896
|
try {
|
|
@@ -1949,10 +1936,27 @@
|
|
|
1949
1936
|
return matches;
|
|
1950
1937
|
},
|
|
1951
1938
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
1952
|
-
|
|
1953
|
-
var _search$__data;
|
|
1939
|
+
resolvedMatches.forEach(async match => {
|
|
1954
1940
|
// Validate the match (loads search params etc)
|
|
1955
1941
|
match.__.validate();
|
|
1942
|
+
});
|
|
1943
|
+
|
|
1944
|
+
// Check each match middleware to see if the route can be accessed
|
|
1945
|
+
await Promise.all(resolvedMatches.map(async match => {
|
|
1946
|
+
try {
|
|
1947
|
+
await (match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
1948
|
+
router: router,
|
|
1949
|
+
match
|
|
1950
|
+
}));
|
|
1951
|
+
} catch (err) {
|
|
1952
|
+
if (!(loaderOpts != null && loaderOpts.preload)) {
|
|
1953
|
+
match.options.onLoadError == null ? void 0 : match.options.onLoadError(err);
|
|
1954
|
+
}
|
|
1955
|
+
throw err;
|
|
1956
|
+
}
|
|
1957
|
+
}));
|
|
1958
|
+
const matchPromises = resolvedMatches.map(async match => {
|
|
1959
|
+
var _search$__data;
|
|
1956
1960
|
const search = match.search;
|
|
1957
1961
|
if ((_search$__data = search.__data) != null && _search$__data.matchId && search.__data.matchId !== match.matchId) {
|
|
1958
1962
|
return;
|
|
@@ -2007,10 +2011,10 @@
|
|
|
2007
2011
|
}
|
|
2008
2012
|
},
|
|
2009
2013
|
invalidateRoute: opts => {
|
|
2010
|
-
var _router$state$
|
|
2014
|
+
var _router$state$pending3;
|
|
2011
2015
|
const next = router.buildNext(opts);
|
|
2012
2016
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
2013
|
-
[...router.state.
|
|
2017
|
+
[...router.state.currentMatches, ...((_router$state$pending3 = router.state.pendingMatches) != null ? _router$state$pending3 : [])].forEach(match => {
|
|
2014
2018
|
if (unloadedMatchIds.includes(match.matchId)) {
|
|
2015
2019
|
match.invalidate();
|
|
2016
2020
|
}
|
|
@@ -2033,15 +2037,14 @@
|
|
|
2033
2037
|
});
|
|
2034
2038
|
const next = router.buildNext(location);
|
|
2035
2039
|
if (opts != null && opts.pending) {
|
|
2036
|
-
|
|
2037
|
-
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
2040
|
+
if (!router.state.pendingLocation) {
|
|
2038
2041
|
return false;
|
|
2039
2042
|
}
|
|
2040
|
-
return !!matchPathname(router.basepath, router.state.
|
|
2043
|
+
return !!matchPathname(router.basepath, router.state.pendingLocation.pathname, _extends({}, opts, {
|
|
2041
2044
|
to: next.pathname
|
|
2042
2045
|
}));
|
|
2043
2046
|
}
|
|
2044
|
-
return !!matchPathname(router.basepath, router.state.
|
|
2047
|
+
return !!matchPathname(router.basepath, router.state.currentLocation.pathname, _extends({}, opts, {
|
|
2045
2048
|
to: next.pathname
|
|
2046
2049
|
}));
|
|
2047
2050
|
},
|
|
@@ -2119,11 +2122,11 @@
|
|
|
2119
2122
|
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
2120
2123
|
|
|
2121
2124
|
// Compare path/hash for matches
|
|
2122
|
-
const pathIsEqual = router.state.
|
|
2123
|
-
const currentPathSplit = router.state.
|
|
2125
|
+
const pathIsEqual = router.state.currentLocation.pathname === next.pathname;
|
|
2126
|
+
const currentPathSplit = router.state.currentLocation.pathname.split('/');
|
|
2124
2127
|
const nextPathSplit = next.pathname.split('/');
|
|
2125
2128
|
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2126
|
-
const hashIsEqual = router.state.
|
|
2129
|
+
const hashIsEqual = router.state.currentLocation.hash === next.hash;
|
|
2127
2130
|
// Combine the matches based on user options
|
|
2128
2131
|
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
2129
2132
|
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
@@ -2150,6 +2153,9 @@
|
|
|
2150
2153
|
router.preloadRoute(nextOpts, {
|
|
2151
2154
|
maxAge: userPreloadMaxAge,
|
|
2152
2155
|
gcMaxAge: userPreloadGcMaxAge
|
|
2156
|
+
}).catch(err => {
|
|
2157
|
+
console.log(err);
|
|
2158
|
+
console.warn('Error preloading route! ☝️');
|
|
2153
2159
|
});
|
|
2154
2160
|
}
|
|
2155
2161
|
};
|
|
@@ -2164,6 +2170,9 @@
|
|
|
2164
2170
|
router.preloadRoute(nextOpts, {
|
|
2165
2171
|
maxAge: userPreloadMaxAge,
|
|
2166
2172
|
gcMaxAge: userPreloadGcMaxAge
|
|
2173
|
+
}).catch(err => {
|
|
2174
|
+
console.log(err);
|
|
2175
|
+
console.warn('Error preloading route! ☝️');
|
|
2167
2176
|
});
|
|
2168
2177
|
}, preloadDelay);
|
|
2169
2178
|
}
|
|
@@ -2246,9 +2255,9 @@
|
|
|
2246
2255
|
if (dest === void 0) {
|
|
2247
2256
|
dest = {};
|
|
2248
2257
|
}
|
|
2249
|
-
const fromPathname = dest.fromCurrent ? router.
|
|
2258
|
+
const fromPathname = dest.fromCurrent ? router.state.latestLocation.pathname : (_dest$from = dest.from) != null ? _dest$from : router.state.latestLocation.pathname;
|
|
2250
2259
|
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2251
|
-
const fromMatches = router.matchRoutes(router.
|
|
2260
|
+
const fromMatches = router.matchRoutes(router.state.latestLocation.pathname, {
|
|
2252
2261
|
strictParseParams: true
|
|
2253
2262
|
});
|
|
2254
2263
|
const toMatches = router.matchRoutes(pathname);
|
|
@@ -2262,7 +2271,7 @@
|
|
|
2262
2271
|
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
|
|
2263
2272
|
|
|
2264
2273
|
// Pre filters first
|
|
2265
|
-
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.
|
|
2274
|
+
const preFilteredSearch = (_dest$__preSearchFilt = dest.__preSearchFilters) != null && _dest$__preSearchFilt.length ? dest.__preSearchFilters.reduce((prev, next) => next(prev), router.state.latestLocation.search) : router.state.latestLocation.search;
|
|
2266
2275
|
|
|
2267
2276
|
// Then the link/navigate function
|
|
2268
2277
|
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
@@ -2272,15 +2281,15 @@
|
|
|
2272
2281
|
|
|
2273
2282
|
// Then post filters
|
|
2274
2283
|
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2275
|
-
const search = replaceEqualDeep(router.
|
|
2284
|
+
const search = replaceEqualDeep(router.state.latestLocation.search, postFilteredSearch);
|
|
2276
2285
|
const searchStr = router.options.stringifySearch(search);
|
|
2277
|
-
let hash = dest.hash === true ? router.
|
|
2286
|
+
let hash = dest.hash === true ? router.state.latestLocation.hash : functionalUpdate(dest.hash, router.state.latestLocation.hash);
|
|
2278
2287
|
hash = hash ? "#" + hash : '';
|
|
2279
2288
|
return {
|
|
2280
2289
|
pathname,
|
|
2281
2290
|
search,
|
|
2282
2291
|
searchStr,
|
|
2283
|
-
state: router.
|
|
2292
|
+
state: router.state.latestLocation.state,
|
|
2284
2293
|
hash,
|
|
2285
2294
|
href: "" + pathname + searchStr + hash,
|
|
2286
2295
|
key: dest.key
|