@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/src/router.ts
CHANGED
|
@@ -285,18 +285,6 @@ export interface RouterOptions<
|
|
|
285
285
|
routeTree?: TRouteTree
|
|
286
286
|
/**
|
|
287
287
|
* The basepath for then entire router. This is useful for mounting a router instance at a subpath.
|
|
288
|
-
*
|
|
289
|
-
* @deprecated - use `rewrite.input` with the new `rewriteBasepath` utility instead:
|
|
290
|
-
* ```ts
|
|
291
|
-
* const router = createRouter({
|
|
292
|
-
* routeTree,
|
|
293
|
-
* rewrite: rewriteBasepath('/basepath')
|
|
294
|
-
* // Or wrap existing rewrite functionality
|
|
295
|
-
* rewrite: rewriteBasepath('/basepath', {
|
|
296
|
-
* output: ({ url }) => {...},
|
|
297
|
-
* input: ({ url }) => {...},
|
|
298
|
-
* })
|
|
299
|
-
* })
|
|
300
288
|
* ```
|
|
301
289
|
* @default '/'
|
|
302
290
|
* @link [API Docs](https://tanstack.com/router/latest/docs/framework/react/api/router/RouterOptionsType#basepath-property)
|
|
@@ -472,8 +460,8 @@ export interface RouterOptions<
|
|
|
472
460
|
* Configures how the router will rewrite the location between the actual href and the internal href of the router.
|
|
473
461
|
*
|
|
474
462
|
* @default undefined
|
|
475
|
-
* @description You can provide a custom rewrite pair (in/out)
|
|
476
|
-
* This is useful for
|
|
463
|
+
* @description You can provide a custom rewrite pair (in/out).
|
|
464
|
+
* This is useful for shifting data from the origin to the path (for things like subdomain routing), or other advanced use cases.
|
|
477
465
|
*/
|
|
478
466
|
rewrite?: LocationRewrite
|
|
479
467
|
origin?: string
|
|
@@ -485,14 +473,12 @@ export interface RouterOptions<
|
|
|
485
473
|
export type LocationRewrite = {
|
|
486
474
|
/**
|
|
487
475
|
* A function that will be called to rewrite the URL before it is interpreted by the router from the history instance.
|
|
488
|
-
* Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
|
|
489
476
|
*
|
|
490
477
|
* @default undefined
|
|
491
478
|
*/
|
|
492
479
|
input?: LocationRewriteFunction
|
|
493
480
|
/**
|
|
494
481
|
* A function that will be called to rewrite the URL before it is committed to the actual history instance from the router.
|
|
495
|
-
* Utilities like `rewriteBasepath` are provided as a convenience for common use cases.
|
|
496
482
|
*
|
|
497
483
|
* @default undefined
|
|
498
484
|
*/
|
|
@@ -884,7 +870,6 @@ export class RouterCore<
|
|
|
884
870
|
rewrite?: LocationRewrite
|
|
885
871
|
origin?: string
|
|
886
872
|
latestLocation!: ParsedLocation<FullSearchSchema<TRouteTree>>
|
|
887
|
-
// @deprecated - basepath functionality is now implemented via the `rewrite` option
|
|
888
873
|
basepath!: string
|
|
889
874
|
routeTree!: TRouteTree
|
|
890
875
|
routesById!: RoutesById<TRouteTree>
|
|
@@ -948,8 +933,13 @@ export class RouterCore<
|
|
|
948
933
|
)
|
|
949
934
|
}
|
|
950
935
|
|
|
936
|
+
const prevOptions = this.options
|
|
937
|
+
const prevBasepath = this.basepath ?? prevOptions?.basepath ?? '/'
|
|
938
|
+
const basepathWasUnset = this.basepath === undefined
|
|
939
|
+
const prevRewriteOption = prevOptions?.rewrite
|
|
940
|
+
|
|
951
941
|
this.options = {
|
|
952
|
-
...
|
|
942
|
+
...prevOptions,
|
|
953
943
|
...newOptions,
|
|
954
944
|
}
|
|
955
945
|
|
|
@@ -976,19 +966,6 @@ export class RouterCore<
|
|
|
976
966
|
this.history = this.options.history
|
|
977
967
|
}
|
|
978
968
|
}
|
|
979
|
-
// For backwards compatibility, we support a basepath option, which we now implement as a rewrite
|
|
980
|
-
if (this.options.basepath) {
|
|
981
|
-
const basepathRewrite = rewriteBasepath({
|
|
982
|
-
basepath: this.options.basepath,
|
|
983
|
-
})
|
|
984
|
-
if (this.options.rewrite) {
|
|
985
|
-
this.rewrite = composeRewrites([basepathRewrite, this.options.rewrite])
|
|
986
|
-
} else {
|
|
987
|
-
this.rewrite = basepathRewrite
|
|
988
|
-
}
|
|
989
|
-
} else {
|
|
990
|
-
this.rewrite = this.options.rewrite
|
|
991
|
-
}
|
|
992
969
|
|
|
993
970
|
this.origin = this.options.origin
|
|
994
971
|
if (!this.origin) {
|
|
@@ -999,6 +976,7 @@ export class RouterCore<
|
|
|
999
976
|
this.origin = 'http://localhost'
|
|
1000
977
|
}
|
|
1001
978
|
}
|
|
979
|
+
|
|
1002
980
|
if (this.history) {
|
|
1003
981
|
this.updateLatestLocation()
|
|
1004
982
|
}
|
|
@@ -1023,6 +1001,48 @@ export class RouterCore<
|
|
|
1023
1001
|
setupScrollRestoration(this)
|
|
1024
1002
|
}
|
|
1025
1003
|
|
|
1004
|
+
let needsLocationUpdate = false
|
|
1005
|
+
const nextBasepath = this.options.basepath ?? '/'
|
|
1006
|
+
const nextRewriteOption = this.options.rewrite
|
|
1007
|
+
const basepathChanged = basepathWasUnset || prevBasepath !== nextBasepath
|
|
1008
|
+
const rewriteChanged = prevRewriteOption !== nextRewriteOption
|
|
1009
|
+
|
|
1010
|
+
if (basepathChanged || rewriteChanged) {
|
|
1011
|
+
this.basepath = nextBasepath
|
|
1012
|
+
|
|
1013
|
+
const rewrites: Array<LocationRewrite> = []
|
|
1014
|
+
if (trimPath(nextBasepath) !== '') {
|
|
1015
|
+
rewrites.push(
|
|
1016
|
+
rewriteBasepath({
|
|
1017
|
+
basepath: nextBasepath,
|
|
1018
|
+
}),
|
|
1019
|
+
)
|
|
1020
|
+
}
|
|
1021
|
+
if (nextRewriteOption) {
|
|
1022
|
+
rewrites.push(nextRewriteOption)
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
this.rewrite =
|
|
1026
|
+
rewrites.length === 0
|
|
1027
|
+
? undefined
|
|
1028
|
+
: rewrites.length === 1
|
|
1029
|
+
? rewrites[0]
|
|
1030
|
+
: composeRewrites(rewrites)
|
|
1031
|
+
|
|
1032
|
+
if (this.history) {
|
|
1033
|
+
this.updateLatestLocation()
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
needsLocationUpdate = true
|
|
1037
|
+
}
|
|
1038
|
+
|
|
1039
|
+
if (needsLocationUpdate && this.__store) {
|
|
1040
|
+
this.__store.state = {
|
|
1041
|
+
...this.state,
|
|
1042
|
+
location: this.latestLocation,
|
|
1043
|
+
}
|
|
1044
|
+
}
|
|
1045
|
+
|
|
1026
1046
|
if (
|
|
1027
1047
|
typeof window !== 'undefined' &&
|
|
1028
1048
|
'CSS' in window &&
|