@tanstack/router-core 1.132.30 → 1.132.33
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 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/router.cjs +35 -13
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +2 -16
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -2
- package/dist/esm/router.d.ts +2 -16
- package/dist/esm/router.js +36 -14
- package/dist/esm/router.js.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +0 -1
- package/src/router.ts +51 -31
package/dist/cjs/router.d.cts
CHANGED
|
@@ -181,18 +181,6 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
181
181
|
routeTree?: TRouteTree;
|
|
182
182
|
/**
|
|
183
183
|
* The basepath for then entire router. This is useful for mounting a router instance at a subpath.
|
|
184
|
-
*
|
|
185
|
-
* @deprecated - use `rewrite.input` with the new `rewriteBasepath` utility instead:
|
|
186
|
-
* ```ts
|
|
187
|
-
* const router = createRouter({
|
|
188
|
-
* routeTree,
|
|
189
|
-
* rewrite: rewriteBasepath('/basepath')
|
|
190
|
-
* // Or wrap existing rewrite functionality
|
|
191
|
-
* rewrite: rewriteBasepath('/basepath', {
|
|
192
|
-
* output: ({ url }) => {...},
|
|
193
|
-
* input: ({ url }) => {...},
|
|
194
|
-
* })
|
|
195
|
-
* })
|
|
196
184
|
* ```
|
|
197
185
|
* @default '/'
|
|
198
186
|
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
|
|
@@ -349,8 +337,8 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
349
337
|
* Configures how the router will rewrite the location between the actual href and the internal href of the router.
|
|
350
338
|
*
|
|
351
339
|
* @default undefined
|
|
352
|
-
* @description You can provide a custom rewrite pair (in/out)
|
|
353
|
-
* This is useful for
|
|
340
|
+
* @description You can provide a custom rewrite pair (in/out).
|
|
341
|
+
* This is useful for shifting data from the origin to the path (for things like subdomain routing), or other advanced use cases.
|
|
354
342
|
*/
|
|
355
343
|
rewrite?: LocationRewrite;
|
|
356
344
|
origin?: string;
|
|
@@ -361,14 +349,12 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
361
349
|
export type LocationRewrite = {
|
|
362
350
|
/**
|
|
363
351
|
* A function that will be called to rewrite the URL before it is interpreted by the router from the history instance.
|
|
364
|
-
* Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
|
|
365
352
|
*
|
|
366
353
|
* @default undefined
|
|
367
354
|
*/
|
|
368
355
|
input?: LocationRewriteFunction;
|
|
369
356
|
/**
|
|
370
357
|
* A function that will be called to rewrite the URL before it is committed to the actual history instance from the router.
|
|
371
|
-
* Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
|
|
372
358
|
*
|
|
373
359
|
* @default undefined
|
|
374
360
|
*/
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -46,5 +46,5 @@ export type { ValidateFromPath, ValidateToPath, ValidateSearch, ValidateParams,
|
|
|
46
46
|
export type { AnySerializationAdapter, SerializationAdapter, ValidateSerializableInput, ValidateSerializableInputResult, SerializerExtensions, ValidateSerializable, RegisteredSerializableInput, SerializableExtensions, DefaultSerializable, Serializable, } from './ssr/serializer/transformer.js';
|
|
47
47
|
export { createSerializationAdapter, makeSerovalPlugin, makeSsrSerovalPlugin, } from './ssr/serializer/transformer.js';
|
|
48
48
|
export { defaultSerovalPlugins } from './ssr/serializer/seroval-plugins.js';
|
|
49
|
-
export {
|
|
49
|
+
export { composeRewrites, executeRewriteInput, executeRewriteOutput, } from './rewrite.js';
|
|
50
50
|
export type { LocationRewrite, LocationRewriteFunction } from './router.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -17,7 +17,7 @@ import { isNotFound, notFound } from "./not-found.js";
|
|
|
17
17
|
import { defaultGetScrollRestorationKey, getCssSelector, handleHashScroll, restoreScroll, scrollRestorationCache, setupScrollRestoration, storageKey } from "./scroll-restoration.js";
|
|
18
18
|
import { createSerializationAdapter, makeSerovalPlugin, makeSsrSerovalPlugin } from "./ssr/serializer/transformer.js";
|
|
19
19
|
import { defaultSerovalPlugins } from "./ssr/serializer/seroval-plugins.js";
|
|
20
|
-
import { composeRewrites, executeRewriteInput, executeRewriteOutput
|
|
20
|
+
import { composeRewrites, executeRewriteInput, executeRewriteOutput } from "./rewrite.js";
|
|
21
21
|
export {
|
|
22
22
|
BaseRootRoute,
|
|
23
23
|
BaseRoute,
|
|
@@ -77,7 +77,6 @@ export {
|
|
|
77
77
|
resolvePath,
|
|
78
78
|
restoreScroll,
|
|
79
79
|
retainSearchParams,
|
|
80
|
-
rewriteBasepath,
|
|
81
80
|
rootRouteId,
|
|
82
81
|
scrollRestorationCache,
|
|
83
82
|
setupScrollRestoration,
|
package/dist/esm/router.d.ts
CHANGED
|
@@ -181,18 +181,6 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
181
181
|
routeTree?: TRouteTree;
|
|
182
182
|
/**
|
|
183
183
|
* The basepath for then entire router. This is useful for mounting a router instance at a subpath.
|
|
184
|
-
*
|
|
185
|
-
* @deprecated - use `rewrite.input` with the new `rewriteBasepath` utility instead:
|
|
186
|
-
* ```ts
|
|
187
|
-
* const router = createRouter({
|
|
188
|
-
* routeTree,
|
|
189
|
-
* rewrite: rewriteBasepath('/basepath')
|
|
190
|
-
* // Or wrap existing rewrite functionality
|
|
191
|
-
* rewrite: rewriteBasepath('/basepath', {
|
|
192
|
-
* output: ({ url }) => {...},
|
|
193
|
-
* input: ({ url }) => {...},
|
|
194
|
-
* })
|
|
195
|
-
* })
|
|
196
184
|
* ```
|
|
197
185
|
* @default '/'
|
|
198
186
|
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
|
|
@@ -349,8 +337,8 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
349
337
|
* Configures how the router will rewrite the location between the actual href and the internal href of the router.
|
|
350
338
|
*
|
|
351
339
|
* @default undefined
|
|
352
|
-
* @description You can provide a custom rewrite pair (in/out)
|
|
353
|
-
* This is useful for
|
|
340
|
+
* @description You can provide a custom rewrite pair (in/out).
|
|
341
|
+
* This is useful for shifting data from the origin to the path (for things like subdomain routing), or other advanced use cases.
|
|
354
342
|
*/
|
|
355
343
|
rewrite?: LocationRewrite;
|
|
356
344
|
origin?: string;
|
|
@@ -361,14 +349,12 @@ export interface RouterOptions<TRouteTree extends AnyRoute, TTrailingSlashOption
|
|
|
361
349
|
export type LocationRewrite = {
|
|
362
350
|
/**
|
|
363
351
|
* A function that will be called to rewrite the URL before it is interpreted by the router from the history instance.
|
|
364
|
-
* Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
|
|
365
352
|
*
|
|
366
353
|
* @default undefined
|
|
367
354
|
*/
|
|
368
355
|
input?: LocationRewriteFunction;
|
|
369
356
|
/**
|
|
370
357
|
* A function that will be called to rewrite the URL before it is committed to the actual history instance from the router.
|
|
371
|
-
* Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
|
|
372
358
|
*
|
|
373
359
|
* @default undefined
|
|
374
360
|
*/
|
package/dist/esm/router.js
CHANGED
|
@@ -2,7 +2,7 @@ import { Store, batch } from "@tanstack/store";
|
|
|
2
2
|
import { createBrowserHistory, parseHref } from "@tanstack/history";
|
|
3
3
|
import { createControlledPromise, deepEqual, replaceEqualDeep, last, findLast, functionalUpdate } from "./utils.js";
|
|
4
4
|
import { processRouteTree } from "./process-route-tree.js";
|
|
5
|
-
import { resolvePath, cleanPath, trimPathRight,
|
|
5
|
+
import { trimPath, resolvePath, cleanPath, trimPathRight, matchPathname, interpolatePath } from "./path.js";
|
|
6
6
|
import { isNotFound } from "./not-found.js";
|
|
7
7
|
import { setupScrollRestoration } from "./scroll-restoration.js";
|
|
8
8
|
import { defaultParseSearch, defaultStringifySearch } from "./searchParams.js";
|
|
@@ -55,8 +55,12 @@ class RouterCore {
|
|
|
55
55
|
"The notFoundRoute API is deprecated and will be removed in the next major version. See https://tanstack.com/router/v1/docs/framework/react/guide/not-found-errors#migrating-from-notfoundroute for more info."
|
|
56
56
|
);
|
|
57
57
|
}
|
|
58
|
+
const prevOptions = this.options;
|
|
59
|
+
const prevBasepath = this.basepath ?? prevOptions?.basepath ?? "/";
|
|
60
|
+
const basepathWasUnset = this.basepath === void 0;
|
|
61
|
+
const prevRewriteOption = prevOptions?.rewrite;
|
|
58
62
|
this.options = {
|
|
59
|
-
...
|
|
63
|
+
...prevOptions,
|
|
60
64
|
...newOptions
|
|
61
65
|
};
|
|
62
66
|
this.isServer = this.options.isServer ?? typeof document === "undefined";
|
|
@@ -75,18 +79,6 @@ class RouterCore {
|
|
|
75
79
|
this.history = this.options.history;
|
|
76
80
|
}
|
|
77
81
|
}
|
|
78
|
-
if (this.options.basepath) {
|
|
79
|
-
const basepathRewrite = rewriteBasepath({
|
|
80
|
-
basepath: this.options.basepath
|
|
81
|
-
});
|
|
82
|
-
if (this.options.rewrite) {
|
|
83
|
-
this.rewrite = composeRewrites([basepathRewrite, this.options.rewrite]);
|
|
84
|
-
} else {
|
|
85
|
-
this.rewrite = basepathRewrite;
|
|
86
|
-
}
|
|
87
|
-
} else {
|
|
88
|
-
this.rewrite = this.options.rewrite;
|
|
89
|
-
}
|
|
90
82
|
this.origin = this.options.origin;
|
|
91
83
|
if (!this.origin) {
|
|
92
84
|
if (!this.isServer) {
|
|
@@ -115,6 +107,36 @@ class RouterCore {
|
|
|
115
107
|
});
|
|
116
108
|
setupScrollRestoration(this);
|
|
117
109
|
}
|
|
110
|
+
let needsLocationUpdate = false;
|
|
111
|
+
const nextBasepath = this.options.basepath ?? "/";
|
|
112
|
+
const nextRewriteOption = this.options.rewrite;
|
|
113
|
+
const basepathChanged = basepathWasUnset || prevBasepath !== nextBasepath;
|
|
114
|
+
const rewriteChanged = prevRewriteOption !== nextRewriteOption;
|
|
115
|
+
if (basepathChanged || rewriteChanged) {
|
|
116
|
+
this.basepath = nextBasepath;
|
|
117
|
+
const rewrites = [];
|
|
118
|
+
if (trimPath(nextBasepath) !== "") {
|
|
119
|
+
rewrites.push(
|
|
120
|
+
rewriteBasepath({
|
|
121
|
+
basepath: nextBasepath
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (nextRewriteOption) {
|
|
126
|
+
rewrites.push(nextRewriteOption);
|
|
127
|
+
}
|
|
128
|
+
this.rewrite = rewrites.length === 0 ? void 0 : rewrites.length === 1 ? rewrites[0] : composeRewrites(rewrites);
|
|
129
|
+
if (this.history) {
|
|
130
|
+
this.updateLatestLocation();
|
|
131
|
+
}
|
|
132
|
+
needsLocationUpdate = true;
|
|
133
|
+
}
|
|
134
|
+
if (needsLocationUpdate && this.__store) {
|
|
135
|
+
this.__store.state = {
|
|
136
|
+
...this.state,
|
|
137
|
+
location: this.latestLocation
|
|
138
|
+
};
|
|
139
|
+
}
|
|
118
140
|
if (typeof window !== "undefined" && "CSS" in window && typeof window.CSS?.supports === "function") {
|
|
119
141
|
this.isViewTransitionTypesSupported = window.CSS.supports(
|
|
120
142
|
"selector(:active-view-transition-type(a)"
|