@tanstack/router-core 1.171.3 → 1.171.5
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/dist/cjs/index.cjs +0 -3
- package/dist/cjs/index.d.cts +1 -2
- package/dist/cjs/rewrite.cjs +1 -6
- package/dist/cjs/rewrite.cjs.map +1 -1
- package/dist/cjs/rewrite.d.cts +0 -4
- package/dist/cjs/router.cjs +9 -2
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +5 -1
- package/dist/cjs/scroll-restoration-inline.cjs +1 -1
- package/dist/cjs/scroll-restoration-inline.cjs.map +1 -1
- package/dist/cjs/scroll-restoration-inline.d.cts +1 -6
- package/dist/cjs/scroll-restoration-script/server.cjs +5 -12
- package/dist/cjs/scroll-restoration-script/server.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.cjs +117 -111
- package/dist/cjs/scroll-restoration.cjs.map +1 -1
- package/dist/cjs/scroll-restoration.d.cts +0 -10
- package/dist/esm/index.d.ts +1 -2
- package/dist/esm/index.js +2 -3
- package/dist/esm/rewrite.d.ts +0 -4
- package/dist/esm/rewrite.js +1 -6
- package/dist/esm/rewrite.js.map +1 -1
- package/dist/esm/router.d.ts +5 -1
- package/dist/esm/router.js +9 -3
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/scroll-restoration-inline.d.ts +1 -6
- package/dist/esm/scroll-restoration-inline.js +1 -1
- package/dist/esm/scroll-restoration-inline.js.map +1 -1
- package/dist/esm/scroll-restoration-script/server.js +5 -12
- package/dist/esm/scroll-restoration-script/server.js.map +1 -1
- package/dist/esm/scroll-restoration.d.ts +0 -10
- package/dist/esm/scroll-restoration.js +118 -111
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -3
- package/src/rewrite.ts +1 -8
- package/src/router.ts +28 -4
- package/src/scroll-restoration-inline.ts +23 -51
- package/src/scroll-restoration-script/server.ts +5 -26
- package/src/scroll-restoration.ts +190 -174
- package/dist/cjs/hash-scroll.cjs +0 -20
- package/dist/cjs/hash-scroll.cjs.map +0 -1
- package/dist/cjs/hash-scroll.d.cts +0 -7
- package/dist/esm/hash-scroll.d.ts +0 -7
- package/dist/esm/hash-scroll.js +0 -20
- package/dist/esm/hash-scroll.js.map +0 -1
- package/src/hash-scroll.ts +0 -21
package/dist/cjs/index.cjs
CHANGED
|
@@ -18,7 +18,6 @@ const require_Matches = require("./Matches.cjs");
|
|
|
18
18
|
const require_route = require("./route.cjs");
|
|
19
19
|
const require_config = require("./config.cjs");
|
|
20
20
|
const require_searchMiddleware = require("./searchMiddleware.cjs");
|
|
21
|
-
const require_hash_scroll = require("./hash-scroll.cjs");
|
|
22
21
|
const require_transformer = require("./ssr/serializer/transformer.cjs");
|
|
23
22
|
const require_RawStream = require("./ssr/serializer/RawStream.cjs");
|
|
24
23
|
const require_seroval_plugins = require("./ssr/serializer/seroval-plugins.cjs");
|
|
@@ -61,7 +60,6 @@ exports.getInitialRouterState = require_router.getInitialRouterState;
|
|
|
61
60
|
exports.getLocationChangeInfo = require_router.getLocationChangeInfo;
|
|
62
61
|
exports.getMatchedRoutes = require_router.getMatchedRoutes;
|
|
63
62
|
exports.getStylesheetHref = require_manifest.getStylesheetHref;
|
|
64
|
-
exports.handleHashScroll = require_hash_scroll.handleHashScroll;
|
|
65
63
|
exports.hasKeys = require_utils.hasKeys;
|
|
66
64
|
exports.interpolatePath = require_path.interpolatePath;
|
|
67
65
|
exports.invariant = require_invariant.invariant;
|
|
@@ -89,7 +87,6 @@ exports.resolveManifestAssetLink = require_manifest.resolveManifestAssetLink;
|
|
|
89
87
|
exports.resolvePath = require_path.resolvePath;
|
|
90
88
|
exports.retainSearchParams = require_searchMiddleware.retainSearchParams;
|
|
91
89
|
exports.rootRouteId = require_root.rootRouteId;
|
|
92
|
-
exports.scrollRestorationCache = require_scroll_restoration.scrollRestorationCache;
|
|
93
90
|
exports.setupScrollRestoration = require_scroll_restoration.setupScrollRestoration;
|
|
94
91
|
exports.storageKey = require_scroll_restoration.storageKey;
|
|
95
92
|
exports.stringifySearchWith = require_searchParams.stringifySearchWith;
|
package/dist/cjs/index.d.cts
CHANGED
|
@@ -40,8 +40,7 @@ export type { Redirect, RedirectOptions, RedirectOptionsRoute, RedirectFnRoute,
|
|
|
40
40
|
export { redirect, isRedirect, isResolvedRedirect, parseRedirect, } from './redirect.cjs';
|
|
41
41
|
export type { NotFoundError } from './not-found.cjs';
|
|
42
42
|
export { isNotFound, notFound } from './not-found.cjs';
|
|
43
|
-
export { defaultGetScrollRestorationKey, getElementScrollRestorationEntry, storageKey,
|
|
44
|
-
export { handleHashScroll } from './hash-scroll.cjs';
|
|
43
|
+
export { defaultGetScrollRestorationKey, getElementScrollRestorationEntry, storageKey, setupScrollRestoration, } from './scroll-restoration.cjs';
|
|
45
44
|
export type { ScrollRestorationOptions, ScrollRestorationEntry, } from './scroll-restoration.cjs';
|
|
46
45
|
export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams, InferFrom, InferTo, InferMaskTo, InferMaskFrom, ValidateNavigateOptions, ValidateNavigateOptionsArray, ValidateRedirectOptions, ValidateRedirectOptionsArray, ValidateId, InferStrict, InferShouldThrow, InferSelected, ValidateUseSearchResult, ValidateUseParamsResult, } from './typePrimitives.cjs';
|
|
47
46
|
export type { AnySerializationAdapter, SerializationAdapter, ValidateSerializableInput, SerializerExtensions, ValidateSerializable, RegisteredSerializableInput, SerializableExtensions, DefaultSerializable, Serializable, TSR_SERIALIZABLE, TsrSerializable, SerializationError, } from './ssr/serializer/transformer.cjs';
|
package/dist/cjs/rewrite.cjs
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const require_path = require("./path.cjs");
|
|
2
2
|
//#region src/rewrite.ts
|
|
3
3
|
/** Compose multiple rewrite pairs into a single in/out rewrite. */
|
|
4
|
-
/** Compose multiple rewrite pairs into a single in/out rewrite. */
|
|
5
4
|
function composeRewrites(rewrites) {
|
|
6
5
|
return {
|
|
7
6
|
input: ({ url }) => {
|
|
@@ -15,13 +14,11 @@ function composeRewrites(rewrites) {
|
|
|
15
14
|
};
|
|
16
15
|
}
|
|
17
16
|
/** Create a rewrite pair that strips/adds a basepath on input/output. */
|
|
18
|
-
/** Create a rewrite pair that strips/adds a basepath on input/output. */
|
|
19
17
|
function rewriteBasepath(opts) {
|
|
20
18
|
const trimmedBasepath = require_path.trimPath(opts.basepath);
|
|
21
19
|
const normalizedBasepath = `/${trimmedBasepath}`;
|
|
22
|
-
const normalizedBasepathWithSlash = `${normalizedBasepath}/`;
|
|
23
20
|
const checkBasepath = opts.caseSensitive ? normalizedBasepath : normalizedBasepath.toLowerCase();
|
|
24
|
-
const checkBasepathWithSlash =
|
|
21
|
+
const checkBasepathWithSlash = `${checkBasepath}/`;
|
|
25
22
|
return {
|
|
26
23
|
input: ({ url }) => {
|
|
27
24
|
const pathname = opts.caseSensitive ? url.pathname : url.pathname.toLowerCase();
|
|
@@ -40,7 +37,6 @@ function rewriteBasepath(opts) {
|
|
|
40
37
|
};
|
|
41
38
|
}
|
|
42
39
|
/** Execute a location input rewrite if provided. */
|
|
43
|
-
/** Execute a location input rewrite if provided. */
|
|
44
40
|
function executeRewriteInput(rewrite, url) {
|
|
45
41
|
const res = rewrite?.input?.({ url });
|
|
46
42
|
if (res) {
|
|
@@ -50,7 +46,6 @@ function executeRewriteInput(rewrite, url) {
|
|
|
50
46
|
return url;
|
|
51
47
|
}
|
|
52
48
|
/** Execute a location output rewrite if provided. */
|
|
53
|
-
/** Execute a location output rewrite if provided. */
|
|
54
49
|
function executeRewriteOutput(rewrite, url) {
|
|
55
50
|
const res = rewrite?.output?.({ url });
|
|
56
51
|
if (res) {
|
package/dist/cjs/rewrite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rewrite.cjs","names":[],"sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\
|
|
1
|
+
{"version":3,"file":"rewrite.cjs","names":[],"sources":["../../src/rewrite.ts"],"sourcesContent":["import { joinPaths, trimPath } from './path'\nimport type { LocationRewrite } from './router'\n\n/** Compose multiple rewrite pairs into a single in/out rewrite. */\nexport function composeRewrites(rewrites: Array<LocationRewrite>) {\n return {\n input: ({ url }) => {\n for (const rewrite of rewrites) {\n url = executeRewriteInput(rewrite, url)\n }\n return url\n },\n output: ({ url }) => {\n for (let i = rewrites.length - 1; i >= 0; i--) {\n url = executeRewriteOutput(rewrites[i], url)\n }\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Create a rewrite pair that strips/adds a basepath on input/output. */\nexport function rewriteBasepath(opts: {\n basepath: string\n caseSensitive?: boolean\n}) {\n const trimmedBasepath = trimPath(opts.basepath)\n const normalizedBasepath = `/${trimmedBasepath}`\n const checkBasepath = opts.caseSensitive\n ? normalizedBasepath\n : normalizedBasepath.toLowerCase()\n const checkBasepathWithSlash = `${checkBasepath}/`\n\n return {\n input: ({ url }) => {\n const pathname = opts.caseSensitive\n ? url.pathname\n : url.pathname.toLowerCase()\n\n // Handle exact basepath match (e.g., /my-app -> /)\n if (pathname === checkBasepath) {\n url.pathname = '/'\n } else if (pathname.startsWith(checkBasepathWithSlash)) {\n // Handle basepath with trailing content (e.g., /my-app/users -> /users)\n url.pathname = url.pathname.slice(normalizedBasepath.length)\n }\n return url\n },\n output: ({ url }) => {\n url.pathname = joinPaths(['/', trimmedBasepath, url.pathname])\n return url\n },\n } satisfies LocationRewrite\n}\n\n/** Execute a location input rewrite if provided. */\nexport function executeRewriteInput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.input?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n\n/** Execute a location output rewrite if provided. */\nexport function executeRewriteOutput(\n rewrite: LocationRewrite | undefined,\n url: URL,\n): URL {\n const res = rewrite?.output?.({ url })\n if (res) {\n if (typeof res === 'string') {\n return new URL(res)\n } else if (res instanceof URL) {\n return res\n }\n }\n return url\n}\n"],"mappings":";;;AAIA,SAAgB,gBAAgB,UAAkC;AAChE,QAAO;EACL,QAAQ,EAAE,UAAU;AAClB,QAAK,MAAM,WAAW,SACpB,OAAM,oBAAoB,SAAS,IAAI;AAEzC,UAAO;;EAET,SAAS,EAAE,UAAU;AACnB,QAAK,IAAI,IAAI,SAAS,SAAS,GAAG,KAAK,GAAG,IACxC,OAAM,qBAAqB,SAAS,IAAI,IAAI;AAE9C,UAAO;;EAEV;;;AAIH,SAAgB,gBAAgB,MAG7B;CACD,MAAM,kBAAkB,aAAA,SAAS,KAAK,SAAS;CAC/C,MAAM,qBAAqB,IAAI;CAC/B,MAAM,gBAAgB,KAAK,gBACvB,qBACA,mBAAmB,aAAa;CACpC,MAAM,yBAAyB,GAAG,cAAc;AAEhD,QAAO;EACL,QAAQ,EAAE,UAAU;GAClB,MAAM,WAAW,KAAK,gBAClB,IAAI,WACJ,IAAI,SAAS,aAAa;AAG9B,OAAI,aAAa,cACf,KAAI,WAAW;YACN,SAAS,WAAW,uBAAuB,CAEpD,KAAI,WAAW,IAAI,SAAS,MAAM,mBAAmB,OAAO;AAE9D,UAAO;;EAET,SAAS,EAAE,UAAU;AACnB,OAAI,WAAW,aAAA,UAAU;IAAC;IAAK;IAAiB,IAAI;IAAS,CAAC;AAC9D,UAAO;;EAEV;;;AAIH,SAAgB,oBACd,SACA,KACK;CACL,MAAM,MAAM,SAAS,QAAQ,EAAE,KAAK,CAAC;AACrC,KAAI;MACE,OAAO,QAAQ,SACjB,QAAO,IAAI,IAAI,IAAI;WACV,eAAe,IACxB,QAAO;;AAGX,QAAO;;;AAIT,SAAgB,qBACd,SACA,KACK;CACL,MAAM,MAAM,SAAS,SAAS,EAAE,KAAK,CAAC;AACtC,KAAI;MACE,OAAO,QAAQ,SACjB,QAAO,IAAI,IAAI,IAAI;WACV,eAAe,IACxB,QAAO;;AAGX,QAAO"}
|
package/dist/cjs/rewrite.d.cts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { LocationRewrite } from './router.cjs';
|
|
2
2
|
/** Compose multiple rewrite pairs into a single in/out rewrite. */
|
|
3
|
-
/** Compose multiple rewrite pairs into a single in/out rewrite. */
|
|
4
3
|
export declare function composeRewrites(rewrites: Array<LocationRewrite>): {
|
|
5
4
|
input: ({ url }: {
|
|
6
5
|
url: URL;
|
|
@@ -10,7 +9,6 @@ export declare function composeRewrites(rewrites: Array<LocationRewrite>): {
|
|
|
10
9
|
}) => URL;
|
|
11
10
|
};
|
|
12
11
|
/** Create a rewrite pair that strips/adds a basepath on input/output. */
|
|
13
|
-
/** Create a rewrite pair that strips/adds a basepath on input/output. */
|
|
14
12
|
export declare function rewriteBasepath(opts: {
|
|
15
13
|
basepath: string;
|
|
16
14
|
caseSensitive?: boolean;
|
|
@@ -23,8 +21,6 @@ export declare function rewriteBasepath(opts: {
|
|
|
23
21
|
}) => URL;
|
|
24
22
|
};
|
|
25
23
|
/** Execute a location input rewrite if provided. */
|
|
26
|
-
/** Execute a location input rewrite if provided. */
|
|
27
24
|
export declare function executeRewriteInput(rewrite: LocationRewrite | undefined, url: URL): URL;
|
|
28
25
|
/** Execute a location output rewrite if provided. */
|
|
29
|
-
/** Execute a location output rewrite if provided. */
|
|
30
26
|
export declare function executeRewriteOutput(rewrite: LocationRewrite | undefined, url: URL): URL;
|
package/dist/cjs/router.cjs
CHANGED
|
@@ -49,6 +49,7 @@ function getLocationChangeInfo(location, resolvedLocation) {
|
|
|
49
49
|
hashChanged: fromLocation?.hash !== toLocation.hash
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
const locationHistoryActions = /* @__PURE__ */ new WeakMap();
|
|
52
53
|
/**
|
|
53
54
|
* Core, framework-agnostic router engine that powers TanStack Router.
|
|
54
55
|
*
|
|
@@ -374,6 +375,7 @@ var RouterCore = class {
|
|
|
374
375
|
return buildWithMatches(opts);
|
|
375
376
|
};
|
|
376
377
|
this.commitLocation = async ({ viewTransition, ignoreBlocker, ...next }) => {
|
|
378
|
+
let historyAction;
|
|
377
379
|
const isSameState = () => {
|
|
378
380
|
const ignoredProps = [
|
|
379
381
|
"key",
|
|
@@ -422,10 +424,11 @@ var RouterCore = class {
|
|
|
422
424
|
}
|
|
423
425
|
nextHistory.state.__hashScrollIntoViewOptions = hashScrollIntoView ?? this.options.defaultHashScrollIntoView ?? true;
|
|
424
426
|
this.shouldViewTransition = viewTransition;
|
|
425
|
-
|
|
427
|
+
historyAction = next.replace ? "REPLACE" : "PUSH";
|
|
428
|
+
this.history[historyAction === "REPLACE" ? "replace" : "push"](nextHistory.publicHref, nextHistory.state, { ignoreBlocker });
|
|
426
429
|
}
|
|
427
430
|
this.resetNextScroll = next.resetScroll ?? true;
|
|
428
|
-
if (!this.history.subscribers.size) this.load();
|
|
431
|
+
if (!this.history.subscribers.size) this.load(historyAction ? { action: { type: historyAction } } : void 0);
|
|
429
432
|
return this.commitLocationPromise;
|
|
430
433
|
};
|
|
431
434
|
this.buildAndCommitLocation = ({ replace, resetScroll, hashScrollIntoView, viewTransition, ignoreBlocker, href, ...rest } = {}) => {
|
|
@@ -530,6 +533,7 @@ var RouterCore = class {
|
|
|
530
533
|
});
|
|
531
534
|
};
|
|
532
535
|
this.load = async (opts) => {
|
|
536
|
+
const historyAction = opts?.action?.type;
|
|
533
537
|
let redirect;
|
|
534
538
|
let notFound;
|
|
535
539
|
let loadPromise;
|
|
@@ -538,6 +542,8 @@ var RouterCore = class {
|
|
|
538
542
|
this.startTransition(async () => {
|
|
539
543
|
try {
|
|
540
544
|
this.beforeLoad();
|
|
545
|
+
if (historyAction) locationHistoryActions.set(this.latestLocation, historyAction);
|
|
546
|
+
else locationHistoryActions.delete(this.latestLocation);
|
|
541
547
|
const next = this.latestLocation;
|
|
542
548
|
const locationChangeInfo = getLocationChangeInfo(next, this.stores.resolvedLocation.get());
|
|
543
549
|
if (!this.stores.redirect.get()) this.emit({
|
|
@@ -1180,6 +1186,7 @@ exports.getInitialRouterState = getInitialRouterState;
|
|
|
1180
1186
|
exports.getLocationChangeInfo = getLocationChangeInfo;
|
|
1181
1187
|
exports.getMatchedRoutes = getMatchedRoutes;
|
|
1182
1188
|
exports.lazyFn = lazyFn;
|
|
1189
|
+
exports.locationHistoryActions = locationHistoryActions;
|
|
1183
1190
|
exports.trailingSlashOptions = trailingSlashOptions;
|
|
1184
1191
|
|
|
1185
1192
|
//# sourceMappingURL=router.cjs.map
|