@tanstack/react-router 0.0.1-beta.225 → 0.0.1-beta.226
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/RouterProvider.js +1 -1
- package/build/cjs/RouterProvider.js.map +1 -1
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +9 -4
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +10 -5
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +284 -284
- package/build/types/RouterProvider.d.ts +1 -6
- package/build/types/route.d.ts +1 -1
- package/build/types/router.d.ts +7 -3
- package/build/umd/index.development.js +11 -5
- 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 +2 -2
- package/src/RouterProvider.tsx +6 -8
- package/src/route.ts +36 -37
- package/src/router.ts +20 -13
|
@@ -3,7 +3,7 @@ import { LinkInfo, LinkOptions, NavigateOptions, ResolveRelativePath, ToOptions
|
|
|
3
3
|
import { ParsedLocation } from './location';
|
|
4
4
|
import { AnyRoute } from './route';
|
|
5
5
|
import { RouteById, RoutePaths } from './routeInfo';
|
|
6
|
-
import { BuildNextOptions,
|
|
6
|
+
import { BuildNextOptions, RegisteredRouter, Router, RouterOptions, RouterState } from './router';
|
|
7
7
|
import { NoInfer } from './utils';
|
|
8
8
|
import { MatchRouteOptions } from './Matches';
|
|
9
9
|
import { RouteMatch } from './Matches';
|
|
@@ -21,11 +21,6 @@ export interface MatchLocation {
|
|
|
21
21
|
export type BuildLinkFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''>(dest: LinkOptions<TRouteTree, TFrom, TTo>) => LinkInfo;
|
|
22
22
|
export type NavigateFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TMaskFrom extends RoutePaths<TRouteTree> = TFrom, TMaskTo extends string = ''>(opts: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>;
|
|
23
23
|
export type MatchRouteFn<TRouteTree extends AnyRoute> = <TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolved = ResolveRelativePath<TFrom, NoInfer<TTo>>>(location: ToOptions<TRouteTree, TFrom, TTo>, opts?: MatchRouteOptions) => false | RouteById<TRouteTree, TResolved>['types']['allParams'];
|
|
24
|
-
export type LoadFn = (opts?: {
|
|
25
|
-
next?: ParsedLocation;
|
|
26
|
-
throwOnError?: boolean;
|
|
27
|
-
__dehydratedMatches?: DehydratedRouteMatch[];
|
|
28
|
-
}) => Promise<void>;
|
|
29
24
|
export type BuildLocationFn<TRouteTree extends AnyRoute> = (opts: BuildNextOptions) => ParsedLocation;
|
|
30
25
|
export type InjectedHtmlEntry = string | (() => Promise<string> | string);
|
|
31
26
|
export declare const routerContext: React.Context<Router<any, Record<string, any>>>;
|
package/build/types/route.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export type MetaOptions = keyof PickRequired<RouteMeta> extends never ? {
|
|
|
29
29
|
} : {
|
|
30
30
|
meta: RouteMeta;
|
|
31
31
|
};
|
|
32
|
-
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderData> & NoInfer<
|
|
32
|
+
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = AnyPathParams, TAllParams extends AnyPathParams = TParams, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchSchema, TFullSearchSchema, TParams, TAllParams, TRouteContext, TAllContext, TLoaderData> & UpdatableRouteOptions<NoInfer<TFullSearchSchema>, NoInfer<TAllParams>, NoInfer<TAllContext>, NoInfer<TLoaderData>>;
|
|
33
33
|
export type ParamsFallback<TPath extends string, TParams> = unknown extends TParams ? Record<ParsePathParams<TPath>, string> : TParams;
|
|
34
34
|
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchSchema extends Record<string, any> = {}, TFullSearchSchema extends Record<string, any> = TSearchSchema, TParams extends AnyPathParams = {}, TAllParams = ParamsFallback<TPath, TParams>, TRouteContext extends RouteContext = RouteContext, TAllContext extends Record<string, any> = AnyContext, TLoaderData extends any = unknown> = RoutePathOptions<TCustomId, TPath> & {
|
|
35
35
|
getParentRoute: () => TParentRoute;
|
package/build/types/router.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { AnyRouteMatch, RouteMatch } from './Matches';
|
|
|
9
9
|
import { ParsedLocation } from './location';
|
|
10
10
|
import { LocationState } from './location';
|
|
11
11
|
import { SearchSerializer, SearchParser } from './searchParams';
|
|
12
|
-
import { BuildLinkFn, BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry,
|
|
12
|
+
import { BuildLinkFn, BuildLocationFn, CommitLocationOptions, InjectedHtmlEntry, MatchRouteFn, NavigateFn } from './RouterProvider';
|
|
13
13
|
declare global {
|
|
14
14
|
interface Window {
|
|
15
15
|
__TSR_DEHYDRATED__?: HydrationCtx;
|
|
@@ -152,12 +152,16 @@ export declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated
|
|
|
152
152
|
commitLocation: ({ startTransition, ...next }: ParsedLocation & CommitLocationOptions) => Promise<void>;
|
|
153
153
|
buildAndCommitLocation: ({ replace, resetScroll, startTransition, ...rest }?: BuildNextOptions & CommitLocationOptions) => Promise<void>;
|
|
154
154
|
navigate: NavigateFn<TRouteTree>;
|
|
155
|
-
loadMatches: ({ checkLatest, matches, preload, }: {
|
|
155
|
+
loadMatches: ({ checkLatest, matches, preload, invalidate, }: {
|
|
156
156
|
checkLatest: () => Promise<void> | undefined;
|
|
157
157
|
matches: AnyRouteMatch[];
|
|
158
158
|
preload?: boolean | undefined;
|
|
159
|
+
invalidate?: boolean | undefined;
|
|
159
160
|
}) => Promise<RouteMatch[]>;
|
|
160
|
-
|
|
161
|
+
invalidate: () => Promise<void>;
|
|
162
|
+
load: (opts?: {
|
|
163
|
+
invalidate?: boolean;
|
|
164
|
+
}) => Promise<void>;
|
|
161
165
|
preloadRoute: (navigateOpts?: BuildNextOptions) => Promise<readonly [RouteMatch<AnyRoute, any>, RouteMatch<AnyRoute, any>[]]>;
|
|
162
166
|
buildLink: BuildLinkFn<TRouteTree>;
|
|
163
167
|
matchRoute: MatchRouteFn<TRouteTree>;
|
|
@@ -169,6 +169,7 @@
|
|
|
169
169
|
* @returns A history instance
|
|
170
170
|
*/
|
|
171
171
|
function createBrowserHistory(opts) {
|
|
172
|
+
console.log('hello');
|
|
172
173
|
const getHref = opts?.getHref ?? (() => `${window.location.pathname}${window.location.search}${window.location.hash}`);
|
|
173
174
|
const createHref = opts?.createHref ?? (path => path);
|
|
174
175
|
let currentLocation = parseLocation(getHref(), window.history.state);
|
|
@@ -1205,7 +1206,7 @@
|
|
|
1205
1206
|
return () => {
|
|
1206
1207
|
unsub();
|
|
1207
1208
|
};
|
|
1208
|
-
}, [history]);
|
|
1209
|
+
}, [router.history]);
|
|
1209
1210
|
React__namespace.useLayoutEffect(() => {
|
|
1210
1211
|
if (!isTransitioning && state.resolvedLocation !== state.location) {
|
|
1211
1212
|
router.emit({
|
|
@@ -2082,7 +2083,8 @@
|
|
|
2082
2083
|
loadMatches = async ({
|
|
2083
2084
|
checkLatest,
|
|
2084
2085
|
matches,
|
|
2085
|
-
preload
|
|
2086
|
+
preload,
|
|
2087
|
+
invalidate
|
|
2086
2088
|
}) => {
|
|
2087
2089
|
let latestPromise;
|
|
2088
2090
|
let firstBadMatchIndex;
|
|
@@ -2198,7 +2200,7 @@
|
|
|
2198
2200
|
// Default to reloading the route all the time
|
|
2199
2201
|
let shouldReload = true;
|
|
2200
2202
|
let shouldReloadDeps = typeof route.options.shouldReload === 'function' ? route.options.shouldReload?.(loaderContext) : !!(route.options.shouldReload ?? true);
|
|
2201
|
-
if (match.cause === 'enter') {
|
|
2203
|
+
if (match.cause === 'enter' || invalidate) {
|
|
2202
2204
|
match.shouldReloadDeps = shouldReloadDeps;
|
|
2203
2205
|
} else if (match.cause === 'stay') {
|
|
2204
2206
|
if (typeof shouldReloadDeps === 'object') {
|
|
@@ -2281,7 +2283,10 @@
|
|
|
2281
2283
|
await Promise.all(matchPromises);
|
|
2282
2284
|
return matches;
|
|
2283
2285
|
};
|
|
2284
|
-
|
|
2286
|
+
invalidate = () => this.load({
|
|
2287
|
+
invalidate: true
|
|
2288
|
+
});
|
|
2289
|
+
load = async opts => {
|
|
2285
2290
|
const promise = new Promise(async (resolve, reject) => {
|
|
2286
2291
|
const next = this.latestLocation;
|
|
2287
2292
|
const prevLocation = this.state.resolvedLocation;
|
|
@@ -2316,7 +2321,8 @@
|
|
|
2316
2321
|
// Load the matches
|
|
2317
2322
|
await this.loadMatches({
|
|
2318
2323
|
matches,
|
|
2319
|
-
checkLatest: () => this.checkLatest(promise)
|
|
2324
|
+
checkLatest: () => this.checkLatest(promise),
|
|
2325
|
+
invalidate: opts?.invalidate
|
|
2320
2326
|
});
|
|
2321
2327
|
} catch (err) {
|
|
2322
2328
|
// swallow this error, since we'll display the
|