@tanstack/router-core 0.0.1-beta.168 → 0.0.1-beta.169
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/router.js +11 -4
- package/build/cjs/router.js.map +1 -1
- package/build/cjs/scroll-restoration.js +3 -0
- package/build/cjs/scroll-restoration.js.map +1 -1
- package/build/esm/index.js +14 -4
- 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 +4 -2
- package/build/umd/index.development.js +14 -4
- 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 +2 -2
- package/src/link.ts +1 -0
- package/src/router.ts +9 -1
- package/src/scroll-restoration.ts +4 -0
package/build/types/index.d.ts
CHANGED
|
@@ -292,6 +292,7 @@ declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends
|
|
|
292
292
|
__store: Store<RouterState<TRouteTree>>;
|
|
293
293
|
state: RouterState<TRouteTree>;
|
|
294
294
|
dehydratedData?: TDehydrated;
|
|
295
|
+
resetNextScroll: boolean;
|
|
295
296
|
constructor(options: RouterConstructorOptions<TRouteTree, TDehydrated>);
|
|
296
297
|
subscribers: Set<RouterListener<RouterEvent>>;
|
|
297
298
|
subscribe: <TType extends keyof RouterEvents>(eventType: TType, fn: ListenerFn<RouterEvents[TType]>) => () => void;
|
|
@@ -325,9 +326,9 @@ declare class Router<TRouteTree extends AnyRoute = AnyRoute, TDehydrated extends
|
|
|
325
326
|
}) => Promise<void>;
|
|
326
327
|
reload: () => Promise<void>;
|
|
327
328
|
resolvePath: (from: string, path: string) => string;
|
|
328
|
-
navigate: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, hash, replace, params, }: NavigateOptions<TRouteTree, TFrom, TTo>) => Promise<void>;
|
|
329
|
+
navigate: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, hash, replace, params, resetScroll, }: NavigateOptions<TRouteTree, TFrom, TTo>) => Promise<void>;
|
|
329
330
|
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"];
|
|
330
|
-
buildLink: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, params, hash, target, replace, activeOptions, preload, preloadDelay: userPreloadDelay, disabled, state, }: LinkOptions<TRouteTree, TFrom, TTo>) => LinkInfo;
|
|
331
|
+
buildLink: <TFrom extends RoutePaths<TRouteTree> = "/", TTo extends string = "">({ from, to, search, params, hash, target, replace, activeOptions, preload, preloadDelay: userPreloadDelay, disabled, state, resetScroll, }: LinkOptions<TRouteTree, TFrom, TTo>) => LinkInfo;
|
|
331
332
|
dehydrate: () => DehydratedRouter;
|
|
332
333
|
hydrate: (__do_not_use_server_ctx?: HydrationCtx) => Promise<void>;
|
|
333
334
|
injectedHtml: (string | (() => Promise<string> | string))[];
|
|
@@ -681,6 +682,7 @@ type RelativeToPathAutoComplete<AllPaths extends string, TFrom extends string, T
|
|
|
681
682
|
} ? never : './' : never) | (TFrom extends `/` ? never : '../') | AllPaths;
|
|
682
683
|
type NavigateOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = ''> = ToOptions<TRouteTree, TFrom, TTo> & {
|
|
683
684
|
replace?: boolean;
|
|
685
|
+
resetScroll?: boolean;
|
|
684
686
|
};
|
|
685
687
|
type ToOptions<TRouteTree extends AnyRoute = AnyRoute, TFrom extends RoutePaths<TRouteTree> = '/', TTo extends string = '', TResolvedTo = ResolveRelativePath<TFrom, NoInfer<TTo>>> = {
|
|
686
688
|
to?: ToPathOption<TRouteTree, TFrom, TTo>;
|
|
@@ -806,6 +806,7 @@
|
|
|
806
806
|
const componentTypes = ['component', 'errorComponent', 'pendingComponent'];
|
|
807
807
|
class Router {
|
|
808
808
|
#unsubHistory;
|
|
809
|
+
resetNextScroll = false;
|
|
809
810
|
constructor(options) {
|
|
810
811
|
this.options = {
|
|
811
812
|
defaultPreloadDelay: 50,
|
|
@@ -1408,7 +1409,8 @@
|
|
|
1408
1409
|
search,
|
|
1409
1410
|
hash,
|
|
1410
1411
|
replace,
|
|
1411
|
-
params
|
|
1412
|
+
params,
|
|
1413
|
+
resetScroll
|
|
1412
1414
|
}) => {
|
|
1413
1415
|
// If this link simply reloads the current route,
|
|
1414
1416
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -1429,7 +1431,8 @@
|
|
|
1429
1431
|
search,
|
|
1430
1432
|
hash,
|
|
1431
1433
|
replace,
|
|
1432
|
-
params
|
|
1434
|
+
params,
|
|
1435
|
+
resetScroll
|
|
1433
1436
|
});
|
|
1434
1437
|
};
|
|
1435
1438
|
matchRoute = (location, opts) => {
|
|
@@ -1469,7 +1472,8 @@
|
|
|
1469
1472
|
preload,
|
|
1470
1473
|
preloadDelay: userPreloadDelay,
|
|
1471
1474
|
disabled,
|
|
1472
|
-
state
|
|
1475
|
+
state,
|
|
1476
|
+
resetScroll
|
|
1473
1477
|
}) => {
|
|
1474
1478
|
// If this link simply reloads the current route,
|
|
1475
1479
|
// make sure it has a new key so it will trigger a data refresh
|
|
@@ -1491,7 +1495,8 @@
|
|
|
1491
1495
|
params,
|
|
1492
1496
|
hash,
|
|
1493
1497
|
replace,
|
|
1494
|
-
state
|
|
1498
|
+
state,
|
|
1499
|
+
resetScroll
|
|
1495
1500
|
};
|
|
1496
1501
|
const next = this.buildNext(nextOpts);
|
|
1497
1502
|
preload = preload ?? this.options.defaultPreload;
|
|
@@ -1809,6 +1814,8 @@
|
|
|
1809
1814
|
id,
|
|
1810
1815
|
...next.state
|
|
1811
1816
|
});
|
|
1817
|
+
this.resetNextScroll = location.resetScroll ?? true;
|
|
1818
|
+
console.log('resetScroll', this.resetNextScroll);
|
|
1812
1819
|
return this.latestLoadPromise;
|
|
1813
1820
|
};
|
|
1814
1821
|
getRouteMatch = id => {
|
|
@@ -2027,6 +2034,9 @@
|
|
|
2027
2034
|
}
|
|
2028
2035
|
function restoreScrollPositions(router, opts) {
|
|
2029
2036
|
if (pathDidChange) {
|
|
2037
|
+
if (!router.resetNextScroll) {
|
|
2038
|
+
return;
|
|
2039
|
+
}
|
|
2030
2040
|
const getKey = opts?.getKey || defaultGetKey;
|
|
2031
2041
|
pathDidChange = false;
|
|
2032
2042
|
const restoreKey = getKey(router.state.location);
|