@tanstack/router-core 0.0.1-beta.21 → 0.0.1-beta.23
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/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 +16 -12
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +132 -132
- package/build/types/index.d.ts +16 -6
- package/build/umd/index.development.js +16 -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/path.ts +0 -4
- 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>;
|
|
@@ -342,6 +346,7 @@ interface AnyAllRouteInfo {
|
|
|
342
346
|
routeInfoByFullPath: Record<string, AnyRouteInfo>;
|
|
343
347
|
routeIds: any;
|
|
344
348
|
routePaths: any;
|
|
349
|
+
fullSearchSchema: Record<string, any>;
|
|
345
350
|
}
|
|
346
351
|
interface DefaultAllRouteInfo {
|
|
347
352
|
routeConfig: RouteConfig;
|
|
@@ -350,6 +355,7 @@ interface DefaultAllRouteInfo {
|
|
|
350
355
|
routeInfoByFullPath: Record<string, RouteInfo>;
|
|
351
356
|
routeIds: string;
|
|
352
357
|
routePaths: string;
|
|
358
|
+
fullSearchSchema: AnySearchSchema;
|
|
353
359
|
}
|
|
354
360
|
interface AllRouteInfo<TRouteConfig extends AnyRouteConfig = RouteConfig> extends RoutesInfoInner<TRouteConfig, ParseRouteConfig<TRouteConfig>> {
|
|
355
361
|
}
|
|
@@ -376,6 +382,7 @@ interface RoutesInfoInner<TRouteConfig extends AnyRouteConfig, TRouteInfo extend
|
|
|
376
382
|
routeInfoByFullPath: TRouteInfoByFullPath;
|
|
377
383
|
routeIds: keyof TRouteInfoById;
|
|
378
384
|
routePaths: keyof TRouteInfoByFullPath;
|
|
385
|
+
fullSearchSchema: Partial<UnionToIntersection<TRouteInfo['fullSearchSchema']>>;
|
|
379
386
|
}
|
|
380
387
|
interface AnyRouteInfo extends RouteInfo<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
381
388
|
}
|
|
@@ -445,7 +452,10 @@ type RouteOptions<TRouteId extends string = string, TPath extends string = strin
|
|
|
445
452
|
loaderMaxAge?: number;
|
|
446
453
|
loaderGcMaxAge?: number;
|
|
447
454
|
action?: ActionFn<TActionPayload, TActionResponse>;
|
|
448
|
-
|
|
455
|
+
beforeLoad?: (opts: {
|
|
456
|
+
context: RouterContext;
|
|
457
|
+
}) => Promise<void> | void;
|
|
458
|
+
onLoaded?: (matchContext: {
|
|
449
459
|
params: TAllParams;
|
|
450
460
|
search: TFullSearchSchema;
|
|
451
461
|
}) => void | undefined | ((match: {
|
|
@@ -607,4 +617,4 @@ declare const defaultStringifySearch: (search: Record<string, any>) => string;
|
|
|
607
617
|
declare function parseSearchWith(parser: (str: string) => any): (searchStr: string) => AnySearchSchema;
|
|
608
618
|
declare function stringifySearchWith(stringify: (search: any) => string): (search: Record<string, any>) => string;
|
|
609
619
|
|
|
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 };
|
|
620
|
+
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
|
}
|
|
@@ -1672,6 +1663,7 @@
|
|
|
1672
1663
|
options: originalOptions,
|
|
1673
1664
|
listeners: [],
|
|
1674
1665
|
// Resolved after construction
|
|
1666
|
+
context: {},
|
|
1675
1667
|
basepath: '',
|
|
1676
1668
|
routeTree: undefined,
|
|
1677
1669
|
routesById: {},
|
|
@@ -1816,7 +1808,19 @@
|
|
|
1816
1808
|
|
|
1817
1809
|
const matches = router.matchRoutes(router.location.pathname, {
|
|
1818
1810
|
strictParseParams: true
|
|
1819
|
-
});
|
|
1811
|
+
}); // Check if each match middleware to see if the route can be accessed
|
|
1812
|
+
|
|
1813
|
+
try {
|
|
1814
|
+
await Promise.all(matches.map(match => match.options.beforeLoad == null ? void 0 : match.options.beforeLoad({
|
|
1815
|
+
context: router.context
|
|
1816
|
+
})));
|
|
1817
|
+
} catch (err) {
|
|
1818
|
+
if (err != null && err.then) {
|
|
1819
|
+
await new Promise(() => {});
|
|
1820
|
+
}
|
|
1821
|
+
|
|
1822
|
+
throw err;
|
|
1823
|
+
}
|
|
1820
1824
|
|
|
1821
1825
|
if (typeof document !== 'undefined') {
|
|
1822
1826
|
router.state = _extends({}, router.state, {
|
|
@@ -1886,7 +1890,7 @@
|
|
|
1886
1890
|
});
|
|
1887
1891
|
});
|
|
1888
1892
|
entering.forEach(d => {
|
|
1889
|
-
d.__.onExit = d.options.
|
|
1893
|
+
d.__.onExit = d.options.onLoaded == null ? void 0 : d.options.onLoaded({
|
|
1890
1894
|
params: d.params,
|
|
1891
1895
|
search: d.search
|
|
1892
1896
|
});
|