@tanstack/router-core 0.0.1-beta.21 → 0.0.1-beta.24
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/packages/router-core/src/path.js +1 -4
- package/build/cjs/packages/router-core/src/path.js.map +1 -1
- package/build/cjs/packages/router-core/src/route.js +1 -0
- package/build/cjs/packages/router-core/src/route.js.map +1 -1
- package/build/cjs/packages/router-core/src/routeConfig.js.map +1 -1
- package/build/cjs/packages/router-core/src/router.js +15 -2
- package/build/cjs/packages/router-core/src/router.js.map +1 -1
- package/build/cjs/packages/router-core/src/utils.js +0 -6
- package/build/cjs/packages/router-core/src/utils.js.map +1 -1
- package/build/esm/index.js +17 -12
- 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 +18 -7
- package/build/umd/index.development.js +17 -12
- 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/link.ts +3 -2
- package/src/path.ts +0 -4
- package/src/route.ts +6 -1
- package/src/routeConfig.ts +5 -1
- package/src/routeInfo.ts +4 -1
- package/src/router.ts +28 -5
- package/src/utils.ts +5 -5
package/build/types/index.d.ts
CHANGED
|
@@ -89,6 +89,7 @@ type PickRequired<T> = {
|
|
|
89
89
|
type Expand<T> = T extends object ? T extends infer O ? {
|
|
90
90
|
[K in keyof O]: O[K];
|
|
91
91
|
} : never : T;
|
|
92
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => any ? I : never;
|
|
92
93
|
type Values<O> = O[ValueKeys<O>];
|
|
93
94
|
type ValueKeys<O> = Extract<keyof O, PropertyKey>;
|
|
94
95
|
type DeepAwaited<T> = T extends Promise<infer A> ? DeepAwaited<A> : T extends Record<infer A, Promise<infer B>> ? {
|
|
@@ -199,9 +200,9 @@ interface LoaderState<TFullSearchSchema extends AnySearchSchema = {}, TAllParams
|
|
|
199
200
|
loadedAt: number;
|
|
200
201
|
loaderContext: LoaderContext<TFullSearchSchema, TAllParams>;
|
|
201
202
|
}
|
|
202
|
-
interface RouterState {
|
|
203
|
+
interface RouterState<TSearchObj extends AnySearchSchema = {}, TState extends LocationState = LocationState> {
|
|
203
204
|
status: 'idle' | 'loading';
|
|
204
|
-
location: Location
|
|
205
|
+
location: Location<TSearchObj, TState>;
|
|
205
206
|
matches: RouteMatch[];
|
|
206
207
|
lastUpdated: number;
|
|
207
208
|
actions: Record<string, Action>;
|
|
@@ -248,6 +249,8 @@ interface DehydratedRouterState extends Pick<RouterState, 'status' | 'location'
|
|
|
248
249
|
}
|
|
249
250
|
interface DehydratedRouteMatch extends Pick<RouteMatch<any, any>, 'matchId' | 'status' | 'routeLoaderData' | 'loaderData' | 'isInvalid' | 'invalidAt'> {
|
|
250
251
|
}
|
|
252
|
+
interface RouterContext {
|
|
253
|
+
}
|
|
251
254
|
interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInfo extends AnyAllRouteInfo = AllRouteInfo<TRouteConfig>> {
|
|
252
255
|
types: {
|
|
253
256
|
RouteConfig: TRouteConfig;
|
|
@@ -256,11 +259,12 @@ interface Router<TRouteConfig extends AnyRouteConfig = RouteConfig, TAllRouteInf
|
|
|
256
259
|
history: BrowserHistory | MemoryHistory | HashHistory;
|
|
257
260
|
options: PickAsRequired<RouterOptions<TRouteConfig>, 'stringifySearch' | 'parseSearch'>;
|
|
258
261
|
basepath: string;
|
|
262
|
+
context: RouterContext;
|
|
259
263
|
listeners: Listener[];
|
|
260
|
-
location: Location
|
|
264
|
+
location: Location<TAllRouteInfo['fullSearchSchema']>;
|
|
261
265
|
navigateTimeout?: Timeout;
|
|
262
266
|
nextAction?: 'push' | 'replace';
|
|
263
|
-
state: RouterState
|
|
267
|
+
state: RouterState<TAllRouteInfo['fullSearchSchema']>;
|
|
264
268
|
routeTree: Route<TAllRouteInfo, RouteInfo>;
|
|
265
269
|
routesById: RoutesById<TAllRouteInfo>;
|
|
266
270
|
navigationPromise: Promise<void>;
|
|
@@ -319,6 +323,7 @@ declare function createRouter<TRouteConfig extends AnyRouteConfig = RouteConfig,
|
|
|
319
323
|
interface AnyRoute extends Route<any, any> {
|
|
320
324
|
}
|
|
321
325
|
interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRouteInfo extends AnyRouteInfo = RouteInfo> {
|
|
326
|
+
routeInfo: TRouteInfo;
|
|
322
327
|
routeId: TRouteInfo['id'];
|
|
323
328
|
routeRouteId: TRouteInfo['routeId'];
|
|
324
329
|
routePath: TRouteInfo['path'];
|
|
@@ -329,7 +334,7 @@ interface Route<TAllRouteInfo extends AnyAllRouteInfo = DefaultAllRouteInfo, TRo
|
|
|
329
334
|
router: Router<TAllRouteInfo['routeConfig'], TAllRouteInfo>;
|
|
330
335
|
buildLink: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>) => LinkInfo;
|
|
331
336
|
matchRoute: <TTo extends string = '.', TResolved extends string = ResolveRelativePath<TRouteInfo['id'], TTo>>(matchLocation: CheckRelativePath<TAllRouteInfo, TRouteInfo['fullPath'], NoInfer<TTo>> & Omit<ToOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>, opts?: MatchRouteOptions) => RouteInfoByPath<TAllRouteInfo, TResolved>['allParams'];
|
|
332
|
-
navigate: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['
|
|
337
|
+
navigate: <TTo extends string = '.'>(options: Omit<LinkOptions<TAllRouteInfo, TRouteInfo['fullPath'], TTo>, 'from'>) => Promise<void>;
|
|
333
338
|
action: unknown extends TRouteInfo['actionResponse'] ? Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']> | undefined : Action<TRouteInfo['actionPayload'], TRouteInfo['actionResponse']>;
|
|
334
339
|
loader: unknown extends TRouteInfo['routeLoaderData'] ? Action<LoaderContext<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams']>, TRouteInfo['routeLoaderData']> | undefined : Loader<TRouteInfo['fullSearchSchema'], TRouteInfo['allParams'], TRouteInfo['routeLoaderData']>;
|
|
335
340
|
}
|
|
@@ -342,6 +347,7 @@ interface AnyAllRouteInfo {
|
|
|
342
347
|
routeInfoByFullPath: Record<string, AnyRouteInfo>;
|
|
343
348
|
routeIds: any;
|
|
344
349
|
routePaths: any;
|
|
350
|
+
fullSearchSchema: Record<string, any>;
|
|
345
351
|
}
|
|
346
352
|
interface DefaultAllRouteInfo {
|
|
347
353
|
routeConfig: RouteConfig;
|
|
@@ -350,6 +356,7 @@ interface DefaultAllRouteInfo {
|
|
|
350
356
|
routeInfoByFullPath: Record<string, RouteInfo>;
|
|
351
357
|
routeIds: string;
|
|
352
358
|
routePaths: string;
|
|
359
|
+
fullSearchSchema: AnySearchSchema;
|
|
353
360
|
}
|
|
354
361
|
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
355
362
|
}
|
|
@@ -376,6 +383,7 @@ interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extend
|
|
|
376
383
|
routeInfoByFullPath: TRouteInfoByFullPath;
|
|
377
384
|
routeIds: keyof TRouteInfoById;
|
|
378
385
|
routePaths: keyof TRouteInfoByFullPath;
|
|
386
|
+
fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>;
|
|
379
387
|
}
|
|
380
388
|
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
381
389
|
}
|
|
@@ -445,7 +453,10 @@ type RouteOptions<TRouteId extends string = string, TPath extends string = strin
|
|
|
445
453
|
loaderMaxAge?: number;
|
|
446
454
|
loaderGcMaxAge?: number;
|
|
447
455
|
action?: ActionFn<TActionPayload, TActionResponse>;
|
|
448
|
-
|
|
456
|
+
beforeLoad?: (opts: {
|
|
457
|
+
context: RouterContext;
|
|
458
|
+
}) => Promise<void> | void;
|
|
459
|
+
onLoaded?: (matchContext: {
|
|
449
460
|
params: TAllParams;
|
|
450
461
|
search: TFullSearchSchema;
|
|
451
462
|
}) => void | undefined | ((match: {
|
|
@@ -607,4 +618,4 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
|
607
618
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
608
619
|
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
609
620
|
|
|
610
|
-
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, 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, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, RelativeToPathAutoComplete, ResolveRelativePath, RootRouteId, Route, RouteConfig, RouteConfigRoute, RouteInfo, RouteInfoById, RouteInfoByPath, RouteMatch, RouteMeta, RouteOptions, Router, RouterOptions, RouterState, RoutesById, RoutesInfoInner, SearchFilter, SearchParser, SearchSchemaValidator, SearchSchemaValidatorFn, SearchSchemaValidatorObj, SearchSerializer, Segment, Split, Timeout, ToIdOption, ToOptions, ToPathOption, 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 };
|
|
621
|
+
export { Action, ActionFn, ActionState, AllRouteInfo, AnyAllRouteInfo, AnyLoaderData, AnyPathParams, AnyRoute, AnyRouteConfig, AnyRouteConfigWithChildren, AnyRouteInfo, AnySearchSchema, BuildNextOptions, CheckId, CheckIdError, CheckPath, CheckPathError, CheckRelativePath, DeepAwaited, DefaultAllRouteInfo, DefinedPathParamWarning, 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, PendingState, PickAsPartial, PickAsRequired, PickExclude, PickExtra, PickExtract, PickRequired, PickUnsafe, 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 };
|
|
@@ -832,12 +832,6 @@
|
|
|
832
832
|
throw new Error(value);
|
|
833
833
|
}
|
|
834
834
|
|
|
835
|
-
// type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (
|
|
836
|
-
// k: infer I,
|
|
837
|
-
// ) => any
|
|
838
|
-
// ? I
|
|
839
|
-
// : never
|
|
840
|
-
|
|
841
835
|
/**
|
|
842
836
|
* This function returns `a` if `b` is deeply equal.
|
|
843
837
|
* If not, it will replace any deeply equal children of `b` with those of `a`.
|
|
@@ -1059,10 +1053,7 @@
|
|
|
1059
1053
|
|
|
1060
1054
|
if (matchLocation.to && !pathParams) {
|
|
1061
1055
|
return;
|
|
1062
|
-
}
|
|
1063
|
-
// return
|
|
1064
|
-
// }
|
|
1065
|
-
|
|
1056
|
+
}
|
|
1066
1057
|
|
|
1067
1058
|
return pathParams != null ? pathParams : {};
|
|
1068
1059
|
}
|
|
@@ -1299,6 +1290,7 @@
|
|
|
1299
1290
|
})();
|
|
1300
1291
|
|
|
1301
1292
|
let route = {
|
|
1293
|
+
routeInfo: undefined,
|
|
1302
1294
|
routeId: id,
|
|
1303
1295
|
routeRouteId: routeId,
|
|
1304
1296
|
routePath,
|
|
@@ -1672,6 +1664,7 @@
|
|
|
1672
1664
|
options: originalOptions,
|
|
1673
1665
|
listeners: [],
|
|
1674
1666
|
// Resolved after construction
|
|
1667
|
+
context: {},
|
|
1675
1668
|
basepath: '',
|
|
1676
1669
|
routeTree: undefined,
|
|
1677
1670
|
routesById: {},
|
|
@@ -1816,7 +1809,19 @@
|
|
|
1816
1809
|
|
|
1817
1810
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1818
1811
|
strictParseParams: true
|
|
1819
|
-
});
|
|
1812
|
+
}); // Check if each match middleware to see if the route can be accessed
|
|
1813
|
+
|
|
1814
|
+
try {
|
|
1815
|
+
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
1816
|
+
context: router.context
|
|
1817
|
+
})));
|
|
1818
|
+
} catch (err) {
|
|
1819
|
+
if (err != null && err.then) {
|
|
1820
|
+
await new Promise(() => {});
|
|
1821
|
+
}
|
|
1822
|
+
|
|
1823
|
+
throw err;
|
|
1824
|
+
}
|
|
1820
1825
|
|
|
1821
1826
|
if (typeof document !== 'undefined') {
|
|
1822
1827
|
router.state = _extends({}, router.state, {
|
|
@@ -1886,7 +1891,7 @@
|
|
|
1886
1891
|
});
|
|
1887
1892
|
});
|
|
1888
1893
|
entering.forEach(d => {
|
|
1889
|
-
d.__.onExit = d.options.
|
|
1894
|
+
d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
|
|
1890
1895
|
params: d.params,
|
|
1891
1896
|
search: d.search
|
|
1892
1897
|
});
|