@tanstack/router-core 0.0.1-beta.176 → 0.0.1-beta.178
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.map +1 -1
- package/build/cjs/router.js +27 -43
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +27 -43
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +124 -124
- package/build/types/fileRoute.d.ts +0 -1
- package/build/types/route.d.ts +11 -10
- package/build/types/router.d.ts +1 -2
- package/build/umd/index.development.js +27 -43
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +2 -2
- package/build/umd/index.production.js.map +1 -1
- package/package.json +1 -1
- package/src/route.ts +36 -48
- package/src/router.ts +33 -50
package/build/types/route.d.ts
CHANGED
|
@@ -58,11 +58,14 @@ export type AnyRouteProps = RegisteredRouteProps<any, any, any, any, any>;
|
|
|
58
58
|
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TLoader, TParentSearchSchema, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext> & UpdatableRouteOptions<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, TRouteContext, TAllContext>;
|
|
59
59
|
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
60
60
|
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TLoader = unknown, TParentSearchSchema extends AnySearchSchema = {}, TSearchSchema extends AnySearchSchema = {}, TFullSearchSchema extends AnySearchSchema = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TParentContext extends AnyContext = AnyContext, TAllParentContext extends AnyContext = AnyContext, TRouteContext extends RouteContext = RouteContext, TAllContext extends AnyContext = AnyContext> = RoutePathOptions<TCustomId, TPath> & {
|
|
61
|
-
layoutLimit?: string;
|
|
62
61
|
getParentRoute: () => TParentRoute;
|
|
63
62
|
validateSearch?: SearchSchemaValidator<TSearchSchema>;
|
|
64
63
|
loader?: LoaderFn<TLoader, TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TAllContext>;
|
|
65
|
-
} & (
|
|
64
|
+
} & (keyof PickRequired<RouteContext> extends never ? {
|
|
65
|
+
beforeLoad?: BeforeLoadFn<TParentRoute, TAllParams, TSearchSchema, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext>;
|
|
66
|
+
} : {
|
|
67
|
+
beforeLoad: BeforeLoadFn<TParentRoute, TAllParams, TSearchSchema, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext>;
|
|
68
|
+
}) & ([TLoader] extends [never] ? {
|
|
66
69
|
loader: 'Loaders must return a type other than never. If you are throwing a redirect() and not returning anything, return a redirect() instead.';
|
|
67
70
|
} : {}) & ({
|
|
68
71
|
parseParams?: (rawParams: IsAny<TPath, any, Record<ParsePathParams<TPath>, string>>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : 'parseParams must return an object';
|
|
@@ -70,21 +73,20 @@ export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId
|
|
|
70
73
|
} | {
|
|
71
74
|
stringifyParams?: never;
|
|
72
75
|
parseParams?: never;
|
|
73
|
-
}) & (keyof PickRequired<RouteContext> extends never ? {
|
|
74
|
-
getContext?: GetContextFn<TParentRoute, TAllParams, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext>;
|
|
75
|
-
} : {
|
|
76
|
-
getContext: GetContextFn<TParentRoute, TAllParams, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext>;
|
|
77
76
|
});
|
|
78
|
-
type
|
|
77
|
+
type BeforeLoadFn<TParentRoute, TAllParams, TSearchSchema, TFullSearchSchema, TParentContext, TAllParentContext, TRouteContext> = (opts: {
|
|
79
78
|
params: TAllParams;
|
|
79
|
+
routeSearch: TSearchSchema;
|
|
80
80
|
search: TFullSearchSchema;
|
|
81
|
+
abortController: AbortController;
|
|
82
|
+
preload: boolean;
|
|
81
83
|
} & (TParentRoute extends undefined ? {
|
|
82
84
|
context?: TAllParentContext;
|
|
83
85
|
parentContext?: TParentContext;
|
|
84
86
|
} : {
|
|
85
87
|
context: TAllParentContext;
|
|
86
88
|
parentContext: TParentContext;
|
|
87
|
-
})) => TRouteContext;
|
|
89
|
+
})) => Promise<TRouteContext> | TRouteContext | void;
|
|
88
90
|
export type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema, TFullSearchSchema extends AnySearchSchema, TAllParams extends AnyPathParams, TRouteContext extends AnyContext, TAllContext extends AnyContext> = MetaOptions & {
|
|
89
91
|
key?: null | false | GetKeyFn<TFullSearchSchema, TAllParams>;
|
|
90
92
|
caseSensitive?: boolean;
|
|
@@ -97,7 +99,6 @@ export type UpdatableRouteOptions<TLoader, TSearchSchema extends AnySearchSchema
|
|
|
97
99
|
preloadMaxAge?: number;
|
|
98
100
|
maxAge?: number;
|
|
99
101
|
gcMaxAge?: number;
|
|
100
|
-
beforeLoad?: (opts: LoaderContext<TSearchSchema, TFullSearchSchema, TAllParams, NoInfer<TRouteContext>, TAllContext>) => Promise<void> | void;
|
|
101
102
|
onError?: (err: any) => void;
|
|
102
103
|
onEnter?: (match: AnyRouteMatch) => void;
|
|
103
104
|
onTransition?: (match: AnyRouteMatch) => void;
|
|
@@ -199,7 +200,7 @@ export declare class Route<TParentRoute extends RouteConstraints['TParentRoute']
|
|
|
199
200
|
routerContext: TRouterContext;
|
|
200
201
|
};
|
|
201
202
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
202
|
-
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext
|
|
203
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TLoader, InferFullSearchSchema<TParentRoute>, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TParentContext, TAllParentContext, TRouteContext, TAllContext>;
|
|
203
204
|
parentRoute: TParentRoute;
|
|
204
205
|
id: TId;
|
|
205
206
|
path: TPath;
|
package/build/types/router.d.ts
CHANGED
|
@@ -209,11 +209,10 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
209
209
|
throwOnError?: boolean;
|
|
210
210
|
debug?: boolean;
|
|
211
211
|
}) => RouteMatch<TRouteTree>[];
|
|
212
|
-
loadMatches: (
|
|
212
|
+
loadMatches: (_resolvedMatches: AnyRouteMatch[], opts?: {
|
|
213
213
|
preload?: boolean;
|
|
214
214
|
maxAge?: number;
|
|
215
215
|
}) => Promise<void>;
|
|
216
|
-
reload: () => Promise<void>;
|
|
217
216
|
resolvePath: (from: string, path: string) => string;
|
|
218
217
|
navigate: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, hash, replace, params, resetScroll, }: NavigateOptions<TRouteTree, TFrom, TTo>) => Promise<void>;
|
|
219
218
|
matchRoute: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "", TResolved extends string = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo, ResolveRelativePath<TFrom, NoInfer<TTo>>>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>["types"]["allParams"];
|
|
@@ -899,7 +899,7 @@
|
|
|
899
899
|
};
|
|
900
900
|
#onFocus = () => {
|
|
901
901
|
if (this.options.refetchOnWindowFocus ?? true) {
|
|
902
|
-
this.
|
|
902
|
+
this.invalidate();
|
|
903
903
|
}
|
|
904
904
|
};
|
|
905
905
|
update = opts => {
|
|
@@ -1235,39 +1235,14 @@
|
|
|
1235
1235
|
return parentSearchInfo;
|
|
1236
1236
|
}
|
|
1237
1237
|
})();
|
|
1238
|
-
Object.assign(match,
|
|
1239
|
-
...searchInfo
|
|
1240
|
-
});
|
|
1241
|
-
const contextInfo = (() => {
|
|
1242
|
-
try {
|
|
1243
|
-
const routeContext = route.options.getContext?.({
|
|
1244
|
-
parentContext: parentMatch?.routeContext ?? {},
|
|
1245
|
-
context: parentMatch?.context ?? this?.options.context ?? {},
|
|
1246
|
-
params: match.params,
|
|
1247
|
-
search: match.search
|
|
1248
|
-
}) || {};
|
|
1249
|
-
const context = {
|
|
1250
|
-
...(parentMatch?.context ?? this?.options.context),
|
|
1251
|
-
...routeContext
|
|
1252
|
-
};
|
|
1253
|
-
return {
|
|
1254
|
-
context,
|
|
1255
|
-
routeContext
|
|
1256
|
-
};
|
|
1257
|
-
} catch (err) {
|
|
1258
|
-
route.options.onError?.(err);
|
|
1259
|
-
throw err;
|
|
1260
|
-
}
|
|
1261
|
-
})();
|
|
1262
|
-
Object.assign(match, {
|
|
1263
|
-
...contextInfo
|
|
1264
|
-
});
|
|
1238
|
+
Object.assign(match, searchInfo);
|
|
1265
1239
|
});
|
|
1266
1240
|
return matches;
|
|
1267
1241
|
};
|
|
1268
|
-
loadMatches = async (
|
|
1242
|
+
loadMatches = async (_resolvedMatches, opts) => {
|
|
1243
|
+
const getFreshMatches = () => _resolvedMatches.map(d => this.getRouteMatch(d.id));
|
|
1269
1244
|
if (!opts?.preload) {
|
|
1270
|
-
|
|
1245
|
+
getFreshMatches().forEach(match => {
|
|
1271
1246
|
// Update each match with its latest route data
|
|
1272
1247
|
this.setRouteMatch(match.id, s => ({
|
|
1273
1248
|
...s,
|
|
@@ -1287,7 +1262,8 @@
|
|
|
1287
1262
|
|
|
1288
1263
|
// Check each match middleware to see if the route can be accessed
|
|
1289
1264
|
try {
|
|
1290
|
-
for (const [index, match] of
|
|
1265
|
+
for (const [index, match] of getFreshMatches().entries()) {
|
|
1266
|
+
const parentMatch = getFreshMatches()[index - 1];
|
|
1291
1267
|
const route = this.getRoute(match.routeId);
|
|
1292
1268
|
const handleError = (err, code) => {
|
|
1293
1269
|
err.routerCode = code;
|
|
@@ -1318,10 +1294,21 @@
|
|
|
1318
1294
|
}
|
|
1319
1295
|
let didError = false;
|
|
1320
1296
|
try {
|
|
1321
|
-
await route.options.beforeLoad?.({
|
|
1297
|
+
const routeContext = (await route.options.beforeLoad?.({
|
|
1322
1298
|
...match,
|
|
1323
|
-
preload: !!opts?.preload
|
|
1324
|
-
|
|
1299
|
+
preload: !!opts?.preload,
|
|
1300
|
+
parentContext: parentMatch?.routeContext ?? {},
|
|
1301
|
+
context: parentMatch?.context ?? this?.options.context ?? {}
|
|
1302
|
+
})) ?? {};
|
|
1303
|
+
const context = {
|
|
1304
|
+
...(parentMatch?.context ?? this?.options.context),
|
|
1305
|
+
...routeContext
|
|
1306
|
+
};
|
|
1307
|
+
this.setRouteMatch(match.id, s => ({
|
|
1308
|
+
...s,
|
|
1309
|
+
context,
|
|
1310
|
+
routeContext
|
|
1311
|
+
}));
|
|
1325
1312
|
} catch (err) {
|
|
1326
1313
|
handleError(err, 'BEFORE_LOAD');
|
|
1327
1314
|
didError = true;
|
|
@@ -1338,7 +1325,7 @@
|
|
|
1338
1325
|
}
|
|
1339
1326
|
throw err;
|
|
1340
1327
|
}
|
|
1341
|
-
const validResolvedMatches =
|
|
1328
|
+
const validResolvedMatches = getFreshMatches().slice(0, firstBadMatchIndex);
|
|
1342
1329
|
const matchPromises = [];
|
|
1343
1330
|
validResolvedMatches.forEach((match, index) => {
|
|
1344
1331
|
matchPromises.push((async () => {
|
|
@@ -1418,13 +1405,6 @@
|
|
|
1418
1405
|
});
|
|
1419
1406
|
await Promise.all(matchPromises);
|
|
1420
1407
|
};
|
|
1421
|
-
reload = () => {
|
|
1422
|
-
return this.navigate({
|
|
1423
|
-
fromCurrent: true,
|
|
1424
|
-
replace: true,
|
|
1425
|
-
search: true
|
|
1426
|
-
});
|
|
1427
|
-
};
|
|
1428
1408
|
resolvePath = (from, path) => {
|
|
1429
1409
|
return resolvePath(this.basepath, from, cleanPath(path));
|
|
1430
1410
|
};
|
|
@@ -1902,7 +1882,11 @@
|
|
|
1902
1882
|
});
|
|
1903
1883
|
}
|
|
1904
1884
|
if (opts?.reload ?? true) {
|
|
1905
|
-
return this.
|
|
1885
|
+
return this.navigate({
|
|
1886
|
+
fromCurrent: true,
|
|
1887
|
+
replace: true,
|
|
1888
|
+
search: true
|
|
1889
|
+
});
|
|
1906
1890
|
}
|
|
1907
1891
|
};
|
|
1908
1892
|
}
|