@tanstack/router-core 1.154.8 → 1.154.13
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/dist/cjs/router.cjs +91 -79
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +1 -1
- package/dist/esm/router.js +91 -79
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +130 -97
- package/src/utils.ts +1 -1
package/dist/cjs/router.cjs
CHANGED
|
@@ -316,14 +316,21 @@ class RouterCore {
|
|
|
316
316
|
path: nextTo,
|
|
317
317
|
params: nextParams
|
|
318
318
|
}).interpolatedPath;
|
|
319
|
-
const
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
);
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
319
|
+
const destMatchResult = this.getMatchedRoutes(interpolatedNextTo);
|
|
320
|
+
let destRoutes = destMatchResult.matchedRoutes;
|
|
321
|
+
const rawParams = destMatchResult.routeParams;
|
|
322
|
+
const isGlobalNotFound = destMatchResult.foundRoute ? destMatchResult.foundRoute.path !== "/" && destMatchResult.routeParams["**"] : path.trimPathRight(interpolatedNextTo);
|
|
323
|
+
let globalNotFoundRouteId;
|
|
324
|
+
if (isGlobalNotFound) {
|
|
325
|
+
if (this.options.notFoundRoute) {
|
|
326
|
+
destRoutes = [...destRoutes, this.options.notFoundRoute];
|
|
327
|
+
} else {
|
|
328
|
+
globalNotFoundRouteId = findGlobalNotFoundRouteId(
|
|
329
|
+
this.options.notFoundMode,
|
|
330
|
+
destRoutes
|
|
331
|
+
);
|
|
332
|
+
}
|
|
333
|
+
}
|
|
327
334
|
if (Object.keys(nextParams).length > 0) {
|
|
328
335
|
for (const route of destRoutes) {
|
|
329
336
|
const fn = route.options.params?.stringify ?? route.options.stringifyParams;
|
|
@@ -382,7 +389,7 @@ class RouterCore {
|
|
|
382
389
|
routes: destRoutes,
|
|
383
390
|
params: snapshotParams,
|
|
384
391
|
searchStr,
|
|
385
|
-
globalNotFoundRouteId
|
|
392
|
+
globalNotFoundRouteId
|
|
386
393
|
});
|
|
387
394
|
const fullPath = `${nextPathname}${searchStr}${hashStr}`;
|
|
388
395
|
const url = new URL(fullPath, this.origin);
|
|
@@ -1106,20 +1113,7 @@ class RouterCore {
|
|
|
1106
1113
|
isGlobalNotFound = true;
|
|
1107
1114
|
}
|
|
1108
1115
|
}
|
|
1109
|
-
globalNotFoundRouteId = (
|
|
1110
|
-
if (!isGlobalNotFound) {
|
|
1111
|
-
return void 0;
|
|
1112
|
-
}
|
|
1113
|
-
if (this.options.notFoundMode !== "root") {
|
|
1114
|
-
for (let i = matchedRoutes.length - 1; i >= 0; i--) {
|
|
1115
|
-
const route = matchedRoutes[i];
|
|
1116
|
-
if (route.children) {
|
|
1117
|
-
return route.id;
|
|
1118
|
-
}
|
|
1119
|
-
}
|
|
1120
|
-
}
|
|
1121
|
-
return root.rootRouteId;
|
|
1122
|
-
})();
|
|
1116
|
+
globalNotFoundRouteId = isGlobalNotFound ? findGlobalNotFoundRouteId(this.options.notFoundMode, matchedRoutes) : void 0;
|
|
1123
1117
|
}
|
|
1124
1118
|
const matches = [];
|
|
1125
1119
|
const getParentContext = (parentMatch) => {
|
|
@@ -1448,76 +1442,94 @@ function applySearchMiddleware({
|
|
|
1448
1442
|
destRoutes,
|
|
1449
1443
|
_includeValidateSearch
|
|
1450
1444
|
}) {
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
1445
|
+
const middleware = buildMiddlewareChain(destRoutes);
|
|
1446
|
+
return middleware(search, dest, _includeValidateSearch ?? false);
|
|
1447
|
+
}
|
|
1448
|
+
function buildMiddlewareChain(destRoutes) {
|
|
1449
|
+
const context = {
|
|
1450
|
+
dest: null,
|
|
1451
|
+
_includeValidateSearch: false,
|
|
1452
|
+
middlewares: []
|
|
1453
|
+
};
|
|
1454
|
+
for (const route of destRoutes) {
|
|
1455
|
+
if ("search" in route.options) {
|
|
1456
|
+
if (route.options.search?.middlewares) {
|
|
1457
|
+
context.middlewares.push(...route.options.search.middlewares);
|
|
1458
|
+
}
|
|
1459
|
+
} else if (route.options.preSearchFilters || route.options.postSearchFilters) {
|
|
1460
|
+
const legacyMiddleware = ({ search, next }) => {
|
|
1461
|
+
let nextSearch = search;
|
|
1462
|
+
if ("preSearchFilters" in route.options && route.options.preSearchFilters) {
|
|
1463
|
+
nextSearch = route.options.preSearchFilters.reduce(
|
|
1464
|
+
(prev, next2) => next2(prev),
|
|
1465
|
+
search
|
|
1466
|
+
);
|
|
1457
1467
|
}
|
|
1458
|
-
|
|
1459
|
-
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
|
|
1466
|
-
|
|
1467
|
-
|
|
1468
|
-
|
|
1469
|
-
|
|
1470
|
-
|
|
1471
|
-
|
|
1472
|
-
|
|
1473
|
-
|
|
1474
|
-
|
|
1475
|
-
|
|
1476
|
-
|
|
1468
|
+
const result = next(nextSearch);
|
|
1469
|
+
if ("postSearchFilters" in route.options && route.options.postSearchFilters) {
|
|
1470
|
+
return route.options.postSearchFilters.reduce(
|
|
1471
|
+
(prev, next2) => next2(prev),
|
|
1472
|
+
result
|
|
1473
|
+
);
|
|
1474
|
+
}
|
|
1475
|
+
return result;
|
|
1476
|
+
};
|
|
1477
|
+
context.middlewares.push(legacyMiddleware);
|
|
1478
|
+
}
|
|
1479
|
+
if (route.options.validateSearch) {
|
|
1480
|
+
const validate = ({ search, next }) => {
|
|
1481
|
+
const result = next(search);
|
|
1482
|
+
if (!context._includeValidateSearch) return result;
|
|
1483
|
+
try {
|
|
1484
|
+
const validatedSearch = {
|
|
1485
|
+
...result,
|
|
1486
|
+
...validateSearch(route.options.validateSearch, result) ?? void 0
|
|
1487
|
+
};
|
|
1488
|
+
return validatedSearch;
|
|
1489
|
+
} catch {
|
|
1477
1490
|
return result;
|
|
1478
|
-
}
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
const validatedSearch = {
|
|
1486
|
-
...result,
|
|
1487
|
-
...validateSearch(route.options.validateSearch, result) ?? void 0
|
|
1488
|
-
};
|
|
1489
|
-
return validatedSearch;
|
|
1490
|
-
} catch {
|
|
1491
|
-
return result;
|
|
1492
|
-
}
|
|
1493
|
-
};
|
|
1494
|
-
middlewares.push(validate);
|
|
1495
|
-
}
|
|
1496
|
-
return acc.concat(middlewares);
|
|
1497
|
-
},
|
|
1498
|
-
[]
|
|
1499
|
-
) ?? [];
|
|
1500
|
-
const final = ({ search: search2 }) => {
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
context.middlewares.push(validate);
|
|
1494
|
+
}
|
|
1495
|
+
}
|
|
1496
|
+
const final = ({ search }) => {
|
|
1497
|
+
const dest = context.dest;
|
|
1501
1498
|
if (!dest.search) {
|
|
1502
1499
|
return {};
|
|
1503
1500
|
}
|
|
1504
1501
|
if (dest.search === true) {
|
|
1505
|
-
return
|
|
1502
|
+
return search;
|
|
1506
1503
|
}
|
|
1507
|
-
return utils.functionalUpdate(dest.search,
|
|
1504
|
+
return utils.functionalUpdate(dest.search, search);
|
|
1508
1505
|
};
|
|
1509
|
-
|
|
1510
|
-
const applyNext = (index, currentSearch) => {
|
|
1511
|
-
if (index >=
|
|
1506
|
+
context.middlewares.push(final);
|
|
1507
|
+
const applyNext = (index, currentSearch, middlewares) => {
|
|
1508
|
+
if (index >= middlewares.length) {
|
|
1512
1509
|
return currentSearch;
|
|
1513
1510
|
}
|
|
1514
|
-
const middleware =
|
|
1511
|
+
const middleware = middlewares[index];
|
|
1515
1512
|
const next = (newSearch) => {
|
|
1516
|
-
return applyNext(index + 1, newSearch);
|
|
1513
|
+
return applyNext(index + 1, newSearch, middlewares);
|
|
1517
1514
|
};
|
|
1518
1515
|
return middleware({ search: currentSearch, next });
|
|
1519
1516
|
};
|
|
1520
|
-
return
|
|
1517
|
+
return function middleware(search, dest, _includeValidateSearch) {
|
|
1518
|
+
context.dest = dest;
|
|
1519
|
+
context._includeValidateSearch = _includeValidateSearch;
|
|
1520
|
+
return applyNext(0, search, context.middlewares);
|
|
1521
|
+
};
|
|
1522
|
+
}
|
|
1523
|
+
function findGlobalNotFoundRouteId(notFoundMode, routes) {
|
|
1524
|
+
if (notFoundMode !== "root") {
|
|
1525
|
+
for (let i = routes.length - 1; i >= 0; i--) {
|
|
1526
|
+
const route = routes[i];
|
|
1527
|
+
if (route.children) {
|
|
1528
|
+
return route.id;
|
|
1529
|
+
}
|
|
1530
|
+
}
|
|
1531
|
+
}
|
|
1532
|
+
return root.rootRouteId;
|
|
1521
1533
|
}
|
|
1522
1534
|
exports.PathParamError = PathParamError;
|
|
1523
1535
|
exports.RouterCore = RouterCore;
|