@tanstack/react-router 1.89.2 → 1.91.0
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/index.d.cts +3 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +19 -23
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +3 -3
- package/dist/cjs/routeInfo.d.cts +3 -3
- package/dist/cjs/router.cjs +28 -24
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +3 -2
- package/dist/cjs/typePrimitives.d.cts +62 -0
- package/dist/cjs/useBlocker.cjs +111 -23
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useBlocker.d.cts +58 -13
- package/dist/cjs/utils.cjs.map +1 -1
- package/dist/cjs/utils.d.cts +3 -2
- package/dist/esm/index.d.ts +3 -1
- package/dist/esm/link.d.ts +19 -23
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +3 -3
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/routeInfo.d.ts +3 -3
- package/dist/esm/router.d.ts +3 -2
- package/dist/esm/router.js +28 -24
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/typePrimitives.d.ts +62 -0
- package/dist/esm/useBlocker.d.ts +58 -13
- package/dist/esm/useBlocker.js +111 -23
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/utils.d.ts +3 -2
- package/dist/esm/utils.js.map +1 -1
- package/package.json +2 -2
- package/src/index.tsx +3 -6
- package/src/link.tsx +107 -144
- package/src/route.ts +14 -7
- package/src/routeInfo.ts +6 -13
- package/src/router.ts +34 -32
- package/src/typePrimitives.ts +168 -0
- package/src/useBlocker.tsx +245 -41
- package/src/utils.ts +9 -5
package/dist/cjs/routeInfo.d.cts
CHANGED
|
@@ -27,7 +27,7 @@ export type RouteByPath<TRouteTree extends AnyRoute, TPath> = Extract<RoutesByPa
|
|
|
27
27
|
export type CodeRoutePaths<TRouteTree extends AnyRoute> = ParseRoute<TRouteTree> extends infer TRoutes extends AnyRoute ? TRoutes['fullPath'] : never;
|
|
28
28
|
export type RoutePaths<TRouteTree extends AnyRoute> = unknown extends TRouteTree ? string : (InferFileRouteTypes<TRouteTree> extends never ? CodeRoutePaths<TRouteTree> : InferFileRouteTypes<TRouteTree>['fullPaths']) | '/';
|
|
29
29
|
export type RouteToPathAlwaysTrailingSlash<TRoute extends AnyRoute> = TRoute['path'] extends '/' ? TRoute['fullPath'] : TRoute['fullPath'] extends '/' ? TRoute['fullPath'] : `${TRoute['fullPath']}/`;
|
|
30
|
-
export type RouteToPathNeverTrailingSlash<TRoute extends AnyRoute> = TRoute['path'] extends '/' ? TRoute['fullPath'] extends '/' ? TRoute['fullPath'] : TRoute['fullPath']
|
|
30
|
+
export type RouteToPathNeverTrailingSlash<TRoute extends AnyRoute> = TRoute['path'] extends '/' ? TRoute['fullPath'] extends '/' ? TRoute['fullPath'] : RemoveTrailingSlashes<TRoute['fullPath']> : TRoute['fullPath'];
|
|
31
31
|
export type RouteToPathPreserveTrailingSlash<TRoute extends AnyRoute> = RouteToPathNeverTrailingSlash<TRoute> | RouteToPathAlwaysTrailingSlash<TRoute>;
|
|
32
32
|
export type RouteToPathByTrailingSlashOption<TRoute extends AnyRoute> = {
|
|
33
33
|
always: RouteToPathAlwaysTrailingSlash<TRoute>;
|
|
@@ -36,9 +36,9 @@ export type RouteToPathByTrailingSlashOption<TRoute extends AnyRoute> = {
|
|
|
36
36
|
};
|
|
37
37
|
export type TrailingSlashOptionByRouter<TRouter extends AnyRouter> = TrailingSlashOption extends TRouter['options']['trailingSlash'] ? 'never' : NonNullable<TRouter['options']['trailingSlash']>;
|
|
38
38
|
export type RouteToByRouter<TRouter extends AnyRouter, TRoute extends AnyRoute> = RouteToPathByTrailingSlashOption<TRoute>[TrailingSlashOptionByRouter<TRouter>];
|
|
39
|
-
export type CodeRouteToPath<TRouter extends AnyRouter
|
|
39
|
+
export type CodeRouteToPath<TRouter extends AnyRouter> = ParseRouteWithoutBranches<TRouter['routeTree']> extends infer TRoute extends AnyRoute ? TRoute extends any ? RouteToByRouter<TRouter, TRoute> : never : never;
|
|
40
40
|
export type FileRouteToPath<TRouter extends AnyRouter, TTo = InferFileRouteTypes<TRouter['routeTree']>['to'], TTrailingSlashOption = TrailingSlashOptionByRouter<TRouter>> = 'never' extends TTrailingSlashOption ? TTo : 'always' extends TTrailingSlashOption ? AddTrailingSlash<TTo> : TTo | AddTrailingSlash<TTo>;
|
|
41
|
-
export type RouteToPath<TRouter extends AnyRouter
|
|
41
|
+
export type RouteToPath<TRouter extends AnyRouter> = unknown extends TRouter ? string : InferFileRouteTypes<TRouter['routeTree']> extends never ? CodeRouteToPath<TRouter> : FileRouteToPath<TRouter>;
|
|
42
42
|
export type CodeRoutesByToPath<TRouter extends AnyRouter> = ParseRouteWithoutBranches<TRouter['routeTree']> extends infer TRoutes extends AnyRoute ? {
|
|
43
43
|
[TRoute in TRoutes as RouteToByRouter<TRouter, TRoute>]: TRoute;
|
|
44
44
|
} : never;
|
package/dist/cjs/router.cjs
CHANGED
|
@@ -218,7 +218,7 @@ class Router {
|
|
|
218
218
|
}
|
|
219
219
|
});
|
|
220
220
|
};
|
|
221
|
-
this.parseLocation = (previousLocation) => {
|
|
221
|
+
this.parseLocation = (previousLocation, locationToParse) => {
|
|
222
222
|
const parse = ({
|
|
223
223
|
pathname,
|
|
224
224
|
search,
|
|
@@ -236,7 +236,7 @@ class Router {
|
|
|
236
236
|
state: utils.replaceEqualDeep(previousLocation == null ? void 0 : previousLocation.state, state)
|
|
237
237
|
};
|
|
238
238
|
};
|
|
239
|
-
const location = parse(this.history.location);
|
|
239
|
+
const location = parse(locationToParse ?? this.history.location);
|
|
240
240
|
const { __tempLocation, __tempKey } = location.state;
|
|
241
241
|
if (__tempLocation && (!__tempKey || __tempKey === this.tempLocationKey)) {
|
|
242
242
|
const parsedTempLocation = parse(__tempLocation);
|
|
@@ -1052,28 +1052,7 @@ class Router {
|
|
|
1052
1052
|
}
|
|
1053
1053
|
};
|
|
1054
1054
|
try {
|
|
1055
|
-
|
|
1056
|
-
if (route.lazyFn) {
|
|
1057
|
-
route._lazyPromise = route.lazyFn().then((lazyRoute) => {
|
|
1058
|
-
const { id: _id, ...options2 } = lazyRoute.options;
|
|
1059
|
-
Object.assign(route.options, options2);
|
|
1060
|
-
});
|
|
1061
|
-
} else {
|
|
1062
|
-
route._lazyPromise = Promise.resolve();
|
|
1063
|
-
}
|
|
1064
|
-
}
|
|
1065
|
-
if (route._componentsPromise === void 0) {
|
|
1066
|
-
route._componentsPromise = route._lazyPromise.then(
|
|
1067
|
-
() => Promise.all(
|
|
1068
|
-
componentTypes.map(async (type) => {
|
|
1069
|
-
const component = route.options[type];
|
|
1070
|
-
if (component == null ? void 0 : component.preload) {
|
|
1071
|
-
await component.preload();
|
|
1072
|
-
}
|
|
1073
|
-
})
|
|
1074
|
-
)
|
|
1075
|
-
);
|
|
1076
|
-
}
|
|
1055
|
+
this.loadRouteChunk(route);
|
|
1077
1056
|
updateMatch(matchId, (prev) => ({
|
|
1078
1057
|
...prev,
|
|
1079
1058
|
isFetching: "loader"
|
|
@@ -1258,6 +1237,31 @@ class Router {
|
|
|
1258
1237
|
};
|
|
1259
1238
|
this.clearCache({ filter });
|
|
1260
1239
|
};
|
|
1240
|
+
this.loadRouteChunk = (route) => {
|
|
1241
|
+
if (route._lazyPromise === void 0) {
|
|
1242
|
+
if (route.lazyFn) {
|
|
1243
|
+
route._lazyPromise = route.lazyFn().then((lazyRoute) => {
|
|
1244
|
+
const { id: _id, ...options2 } = lazyRoute.options;
|
|
1245
|
+
Object.assign(route.options, options2);
|
|
1246
|
+
});
|
|
1247
|
+
} else {
|
|
1248
|
+
route._lazyPromise = Promise.resolve();
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
if (route._componentsPromise === void 0) {
|
|
1252
|
+
route._componentsPromise = route._lazyPromise.then(
|
|
1253
|
+
() => Promise.all(
|
|
1254
|
+
componentTypes.map(async (type) => {
|
|
1255
|
+
const component = route.options[type];
|
|
1256
|
+
if (component == null ? void 0 : component.preload) {
|
|
1257
|
+
await component.preload();
|
|
1258
|
+
}
|
|
1259
|
+
})
|
|
1260
|
+
)
|
|
1261
|
+
);
|
|
1262
|
+
}
|
|
1263
|
+
return route._componentsPromise;
|
|
1264
|
+
};
|
|
1261
1265
|
this.preloadRoute = async (opts) => {
|
|
1262
1266
|
const next = this.buildLocation(opts);
|
|
1263
1267
|
let matches = this.matchRoutes(next, {
|