@tanstack/router-core 1.125.3 → 1.126.2
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/RouterProvider.d.cts +1 -0
- package/dist/cjs/router.cjs +23 -9
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -0
- package/dist/esm/RouterProvider.d.ts +1 -0
- package/dist/esm/router.d.ts +2 -0
- package/dist/esm/router.js +23 -9
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/RouterProvider.ts +1 -0
- package/src/router.ts +35 -11
package/dist/cjs/router.d.cts
CHANGED
|
@@ -340,6 +340,7 @@ export interface BuildNextOptions {
|
|
|
340
340
|
href?: string;
|
|
341
341
|
_fromLocation?: ParsedLocation;
|
|
342
342
|
unsafeRelative?: 'path';
|
|
343
|
+
_isNavigate?: boolean;
|
|
343
344
|
}
|
|
344
345
|
type NavigationEventInfo = {
|
|
345
346
|
fromLocation?: ParsedLocation;
|
|
@@ -537,6 +538,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
|
|
|
537
538
|
getMatchedRoutes: GetMatchRoutesFn;
|
|
538
539
|
cancelMatch: (id: string) => void;
|
|
539
540
|
cancelMatches: () => void;
|
|
541
|
+
private comparePaths;
|
|
540
542
|
buildLocation: BuildLocationFn;
|
|
541
543
|
commitLocationPromise: undefined | ControlledPromise<void>;
|
|
542
544
|
commitLocation: CommitLocationFn;
|
|
@@ -23,4 +23,5 @@ export type NavigateFn = <TRouter extends RegisteredRouter, TTo extends string |
|
|
|
23
23
|
export type BuildLocationFn = <TRouter extends RegisteredRouter, TTo extends string | undefined, TFrom extends RoutePaths<TRouter['routeTree']> | string = string, TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom, TMaskTo extends string = ''>(opts: ToOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
24
24
|
leaveParams?: boolean;
|
|
25
25
|
_includeValidateSearch?: boolean;
|
|
26
|
+
_isNavigate?: boolean;
|
|
26
27
|
}) => ParsedLocation;
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -340,6 +340,7 @@ export interface BuildNextOptions {
|
|
|
340
340
|
href?: string;
|
|
341
341
|
_fromLocation?: ParsedLocation;
|
|
342
342
|
unsafeRelative?: 'path';
|
|
343
|
+
_isNavigate?: boolean;
|
|
343
344
|
}
|
|
344
345
|
type NavigationEventInfo = {
|
|
345
346
|
fromLocation?: ParsedLocation;
|
|
@@ -537,6 +538,7 @@ export declare class RouterCore<in out TRouteTree extends AnyRoute, in out TTrai
|
|
|
537
538
|
getMatchedRoutes: GetMatchRoutesFn;
|
|
538
539
|
cancelMatch: (id: string) => void;
|
|
539
540
|
cancelMatches: () => void;
|
|
541
|
+
private comparePaths;
|
|
540
542
|
buildLocation: BuildLocationFn;
|
|
541
543
|
commitLocationPromise: undefined | ControlledPromise<void>;
|
|
542
544
|
commitLocation: CommitLocationFn;
|
package/dist/esm/router.js
CHANGED
|
@@ -229,21 +229,31 @@ class RouterCore {
|
|
|
229
229
|
const build = (dest = {}) => {
|
|
230
230
|
var _a;
|
|
231
231
|
const currentLocation = dest._fromLocation || this.latestLocation;
|
|
232
|
-
const
|
|
232
|
+
const allCurrentLocationMatches = this.matchRoutes(currentLocation, {
|
|
233
233
|
_buildLocation: true
|
|
234
234
|
});
|
|
235
|
-
const lastMatch = last(
|
|
235
|
+
const lastMatch = last(allCurrentLocationMatches);
|
|
236
236
|
let fromPath = lastMatch.fullPath;
|
|
237
|
-
const
|
|
237
|
+
const toPath = dest.to ? this.resolvePathWithBase(fromPath, `${dest.to}`) : this.resolvePathWithBase(fromPath, ".");
|
|
238
|
+
const routeIsChanging = !!dest.to && !this.comparePaths(dest.to.toString(), fromPath) && !this.comparePaths(toPath, fromPath);
|
|
238
239
|
if (dest.unsafeRelative === "path") {
|
|
239
240
|
fromPath = currentLocation.pathname;
|
|
240
241
|
} else if (routeIsChanging && dest.from) {
|
|
241
242
|
fromPath = dest.from;
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
243
|
+
if (process.env.NODE_ENV !== "production" && dest._isNavigate) {
|
|
244
|
+
const allFromMatches = this.getMatchedRoutes(
|
|
245
|
+
dest.from,
|
|
246
|
+
void 0
|
|
247
|
+
).matchedRoutes;
|
|
248
|
+
const matchedFrom = [...allCurrentLocationMatches].reverse().find((d) => {
|
|
249
|
+
return this.comparePaths(d.fullPath, fromPath);
|
|
250
|
+
});
|
|
251
|
+
const matchedCurrent = [...allFromMatches].reverse().find((d) => {
|
|
252
|
+
return this.comparePaths(d.fullPath, currentLocation.pathname);
|
|
253
|
+
});
|
|
254
|
+
if (!matchedFrom && !matchedCurrent) {
|
|
255
|
+
console.warn(`Could not find match for from: ${fromPath}`);
|
|
256
|
+
}
|
|
247
257
|
}
|
|
248
258
|
}
|
|
249
259
|
const fromSearch = lastMatch.search;
|
|
@@ -481,7 +491,8 @@ class RouterCore {
|
|
|
481
491
|
return this.buildAndCommitLocation({
|
|
482
492
|
...rest,
|
|
483
493
|
href,
|
|
484
|
-
to
|
|
494
|
+
to,
|
|
495
|
+
_isNavigate: true
|
|
485
496
|
});
|
|
486
497
|
};
|
|
487
498
|
this.beforeLoad = () => {
|
|
@@ -1668,6 +1679,9 @@ class RouterCore {
|
|
|
1668
1679
|
});
|
|
1669
1680
|
return matches;
|
|
1670
1681
|
}
|
|
1682
|
+
comparePaths(path1, path2) {
|
|
1683
|
+
return path1.replace(/(.+)\/$/, "$1") === path2.replace(/(.+)\/$/, "$1");
|
|
1684
|
+
}
|
|
1671
1685
|
}
|
|
1672
1686
|
class SearchParamError extends Error {
|
|
1673
1687
|
}
|