@tanstack/router-core 0.0.1-beta.35 → 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/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 -82
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +95 -85
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +134 -134
- package/build/types/index.d.ts +9 -12
- package/build/umd/index.development.js +95 -85
- 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/route.ts +0 -1
- package/src/routeConfig.ts +7 -2
- package/src/routeMatch.ts +4 -2
- package/src/router.ts +147 -119
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 };
|
|
@@ -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,51 +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
|
-
console.
|
|
1756
|
-
invariant(false,
|
|
1738
|
+
console.log(err);
|
|
1739
|
+
invariant(false, 'Matches failed to load due to error above ☝️. Navigation cancelled!');
|
|
1757
1740
|
}
|
|
1758
|
-
router.notify();
|
|
1759
|
-
|
|
1760
|
-
// Load the matches
|
|
1761
|
-
await router.loadMatches(matches);
|
|
1762
1741
|
if (router.startedLoadingAt !== id) {
|
|
1763
1742
|
// Ignore side-effects of match loading
|
|
1764
1743
|
return router.navigationPromise;
|
|
1765
1744
|
}
|
|
1766
|
-
const previousMatches = router.state.
|
|
1745
|
+
const previousMatches = router.state.currentMatches;
|
|
1767
1746
|
const exiting = [],
|
|
1768
1747
|
staying = [];
|
|
1769
1748
|
previousMatches.forEach(d => {
|
|
@@ -1822,10 +1801,11 @@
|
|
|
1822
1801
|
}
|
|
1823
1802
|
});
|
|
1824
1803
|
router.state = _extends({}, router.state, {
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1804
|
+
status: 'idle',
|
|
1805
|
+
currentLocation: router.state.latestLocation,
|
|
1806
|
+
currentMatches: matches,
|
|
1807
|
+
pendingLocation: undefined,
|
|
1808
|
+
pendingMatches: undefined
|
|
1829
1809
|
});
|
|
1830
1810
|
router.notify();
|
|
1831
1811
|
router.resolveNavigation();
|
|
@@ -1851,7 +1831,7 @@
|
|
|
1851
1831
|
},
|
|
1852
1832
|
loadRoute: async function loadRoute(navigateOpts) {
|
|
1853
1833
|
if (navigateOpts === void 0) {
|
|
1854
|
-
navigateOpts = router.
|
|
1834
|
+
navigateOpts = router.state.latestLocation;
|
|
1855
1835
|
}
|
|
1856
1836
|
const next = router.buildNext(navigateOpts);
|
|
1857
1837
|
const matches = router.matchRoutes(next.pathname, {
|
|
@@ -1863,7 +1843,7 @@
|
|
|
1863
1843
|
preloadRoute: async function preloadRoute(navigateOpts, loaderOpts) {
|
|
1864
1844
|
var _ref3, _ref4, _loaderOpts$maxAge, _ref5, _ref6, _loaderOpts$gcMaxAge;
|
|
1865
1845
|
if (navigateOpts === void 0) {
|
|
1866
|
-
navigateOpts = router.
|
|
1846
|
+
navigateOpts = router.state.latestLocation;
|
|
1867
1847
|
}
|
|
1868
1848
|
const next = router.buildNext(navigateOpts);
|
|
1869
1849
|
const matches = router.matchRoutes(next.pathname, {
|
|
@@ -1877,13 +1857,13 @@
|
|
|
1877
1857
|
return matches;
|
|
1878
1858
|
},
|
|
1879
1859
|
matchRoutes: (pathname, opts) => {
|
|
1880
|
-
var _router$state$
|
|
1860
|
+
var _router$state$pending2;
|
|
1881
1861
|
router.cleanMatchCache();
|
|
1882
1862
|
const matches = [];
|
|
1883
1863
|
if (!router.routeTree) {
|
|
1884
1864
|
return matches;
|
|
1885
1865
|
}
|
|
1886
|
-
const existingMatches = [...router.state.
|
|
1866
|
+
const existingMatches = [...router.state.currentMatches, ...((_router$state$pending2 = router.state.pendingMatches) != null ? _router$state$pending2 : [])];
|
|
1887
1867
|
const recurse = async routes => {
|
|
1888
1868
|
var _parentMatch$params, _router$options$filte, _foundRoute$childRout;
|
|
1889
1869
|
const parentMatch = last(matches);
|
|
@@ -1902,7 +1882,15 @@
|
|
|
1902
1882
|
fuzzy,
|
|
1903
1883
|
caseSensitive: (_route$options$caseSe = route.options.caseSensitive) != null ? _route$options$caseSe : router.options.caseSensitive
|
|
1904
1884
|
});
|
|
1905
|
-
|
|
1885
|
+
|
|
1886
|
+
// console.log(
|
|
1887
|
+
// router.basepath,
|
|
1888
|
+
// route.fullPath,
|
|
1889
|
+
// fuzzy,
|
|
1890
|
+
// pathname,
|
|
1891
|
+
// matchParams,
|
|
1892
|
+
// )
|
|
1893
|
+
|
|
1906
1894
|
if (matchParams) {
|
|
1907
1895
|
let parsedParams;
|
|
1908
1896
|
try {
|
|
@@ -1948,10 +1936,27 @@
|
|
|
1948
1936
|
return matches;
|
|
1949
1937
|
},
|
|
1950
1938
|
loadMatches: async (resolvedMatches, loaderOpts) => {
|
|
1951
|
-
|
|
1952
|
-
var _search$__data;
|
|
1939
|
+
resolvedMatches.forEach(async match => {
|
|
1953
1940
|
// Validate the match (loads search params etc)
|
|
1954
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;
|
|
1955
1960
|
const search = match.search;
|
|
1956
1961
|
if ((_search$__data = search.__data) != null && _search$__data.matchId && search.__data.matchId !== match.matchId) {
|
|
1957
1962
|
return;
|
|
@@ -2006,10 +2011,10 @@
|
|
|
2006
2011
|
}
|
|
2007
2012
|
},
|
|
2008
2013
|
invalidateRoute: opts => {
|
|
2009
|
-
var _router$state$
|
|
2014
|
+
var _router$state$pending3;
|
|
2010
2015
|
const next = router.buildNext(opts);
|
|
2011
2016
|
const unloadedMatchIds = router.matchRoutes(next.pathname).map(d => d.matchId);
|
|
2012
|
-
[...router.state.
|
|
2017
|
+
[...router.state.currentMatches, ...((_router$state$pending3 = router.state.pendingMatches) != null ? _router$state$pending3 : [])].forEach(match => {
|
|
2013
2018
|
if (unloadedMatchIds.includes(match.matchId)) {
|
|
2014
2019
|
match.invalidate();
|
|
2015
2020
|
}
|
|
@@ -2032,15 +2037,14 @@
|
|
|
2032
2037
|
});
|
|
2033
2038
|
const next = router.buildNext(location);
|
|
2034
2039
|
if (opts != null && opts.pending) {
|
|
2035
|
-
|
|
2036
|
-
if (!((_router$state$pending7 = router.state.pending) != null && _router$state$pending7.location)) {
|
|
2040
|
+
if (!router.state.pendingLocation) {
|
|
2037
2041
|
return false;
|
|
2038
2042
|
}
|
|
2039
|
-
return !!matchPathname(router.basepath, router.state.
|
|
2043
|
+
return !!matchPathname(router.basepath, router.state.pendingLocation.pathname, _extends({}, opts, {
|
|
2040
2044
|
to: next.pathname
|
|
2041
2045
|
}));
|
|
2042
2046
|
}
|
|
2043
|
-
return !!matchPathname(router.basepath, router.state.
|
|
2047
|
+
return !!matchPathname(router.basepath, router.state.currentLocation.pathname, _extends({}, opts, {
|
|
2044
2048
|
to: next.pathname
|
|
2045
2049
|
}));
|
|
2046
2050
|
},
|
|
@@ -2118,11 +2122,11 @@
|
|
|
2118
2122
|
const preloadDelay = (_ref9 = userPreloadDelay != null ? userPreloadDelay : router.options.defaultPreloadDelay) != null ? _ref9 : 0;
|
|
2119
2123
|
|
|
2120
2124
|
// Compare path/hash for matches
|
|
2121
|
-
const pathIsEqual = router.state.
|
|
2122
|
-
const currentPathSplit = router.state.
|
|
2125
|
+
const pathIsEqual = router.state.currentLocation.pathname === next.pathname;
|
|
2126
|
+
const currentPathSplit = router.state.currentLocation.pathname.split('/');
|
|
2123
2127
|
const nextPathSplit = next.pathname.split('/');
|
|
2124
2128
|
const pathIsFuzzyEqual = nextPathSplit.every((d, i) => d === currentPathSplit[i]);
|
|
2125
|
-
const hashIsEqual = router.state.
|
|
2129
|
+
const hashIsEqual = router.state.currentLocation.hash === next.hash;
|
|
2126
2130
|
// Combine the matches based on user options
|
|
2127
2131
|
const pathTest = activeOptions != null && activeOptions.exact ? pathIsEqual : pathIsFuzzyEqual;
|
|
2128
2132
|
const hashTest = activeOptions != null && activeOptions.includeHash ? hashIsEqual : true;
|
|
@@ -2149,6 +2153,9 @@
|
|
|
2149
2153
|
router.preloadRoute(nextOpts, {
|
|
2150
2154
|
maxAge: userPreloadMaxAge,
|
|
2151
2155
|
gcMaxAge: userPreloadGcMaxAge
|
|
2156
|
+
}).catch(err => {
|
|
2157
|
+
console.log(err);
|
|
2158
|
+
console.warn('Error preloading route! ☝️');
|
|
2152
2159
|
});
|
|
2153
2160
|
}
|
|
2154
2161
|
};
|
|
@@ -2163,6 +2170,9 @@
|
|
|
2163
2170
|
router.preloadRoute(nextOpts, {
|
|
2164
2171
|
maxAge: userPreloadMaxAge,
|
|
2165
2172
|
gcMaxAge: userPreloadGcMaxAge
|
|
2173
|
+
}).catch(err => {
|
|
2174
|
+
console.log(err);
|
|
2175
|
+
console.warn('Error preloading route! ☝️');
|
|
2166
2176
|
});
|
|
2167
2177
|
}, preloadDelay);
|
|
2168
2178
|
}
|
|
@@ -2245,9 +2255,9 @@
|
|
|
2245
2255
|
if (dest === void 0) {
|
|
2246
2256
|
dest = {};
|
|
2247
2257
|
}
|
|
2248
|
-
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;
|
|
2249
2259
|
let pathname = resolvePath((_router$basepath = router.basepath) != null ? _router$basepath : '/', fromPathname, "" + ((_dest$to = dest.to) != null ? _dest$to : '.'));
|
|
2250
|
-
const fromMatches = router.matchRoutes(router.
|
|
2260
|
+
const fromMatches = router.matchRoutes(router.state.latestLocation.pathname, {
|
|
2251
2261
|
strictParseParams: true
|
|
2252
2262
|
});
|
|
2253
2263
|
const toMatches = router.matchRoutes(pathname);
|
|
@@ -2261,7 +2271,7 @@
|
|
|
2261
2271
|
pathname = interpolatePath(pathname, nextParams != null ? nextParams : {});
|
|
2262
2272
|
|
|
2263
2273
|
// Pre filters first
|
|
2264
|
-
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;
|
|
2265
2275
|
|
|
2266
2276
|
// Then the link/navigate function
|
|
2267
2277
|
const destSearch = dest.search === true ? preFilteredSearch // Preserve resolvedFrom true
|
|
@@ -2271,15 +2281,15 @@
|
|
|
2271
2281
|
|
|
2272
2282
|
// Then post filters
|
|
2273
2283
|
const postFilteredSearch = (_dest$__postSearchFil = dest.__postSearchFilters) != null && _dest$__postSearchFil.length ? dest.__postSearchFilters.reduce((prev, next) => next(prev), destSearch) : destSearch;
|
|
2274
|
-
const search = replaceEqualDeep(router.
|
|
2284
|
+
const search = replaceEqualDeep(router.state.latestLocation.search, postFilteredSearch);
|
|
2275
2285
|
const searchStr = router.options.stringifySearch(search);
|
|
2276
|
-
let hash = dest.hash === true ? router.
|
|
2286
|
+
let hash = dest.hash === true ? router.state.latestLocation.hash : functionalUpdate(dest.hash, router.state.latestLocation.hash);
|
|
2277
2287
|
hash = hash ? "#" + hash : '';
|
|
2278
2288
|
return {
|
|
2279
2289
|
pathname,
|
|
2280
2290
|
search,
|
|
2281
2291
|
searchStr,
|
|
2282
|
-
state: router.
|
|
2292
|
+
state: router.state.latestLocation.state,
|
|
2283
2293
|
hash,
|
|
2284
2294
|
href: "" + pathname + searchStr + hash,
|
|
2285
2295
|
key: dest.key
|