@tanstack/router-core 0.0.1-beta.33 → 0.0.1-beta.34
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/path.js +9 -4
- package/build/cjs/path.js.map +1 -1
- package/build/cjs/router.js +10 -8
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +19 -12
- 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 +2 -2
- package/build/umd/index.development.js +19 -12
- 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 +1 -1
- package/src/path.ts +10 -2
- package/src/router.ts +15 -10
package/package.json
CHANGED
package/src/path.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import invariant from 'tiny-invariant'
|
|
1
2
|
import { AnyPathParams } from './routeConfig'
|
|
2
3
|
import { MatchLocation } from './router'
|
|
3
4
|
import { last } from './utils'
|
|
@@ -145,10 +146,11 @@ export function interpolatePath(
|
|
|
145
146
|
}
|
|
146
147
|
|
|
147
148
|
export function matchPathname(
|
|
149
|
+
basepath: string,
|
|
148
150
|
currentPathname: string,
|
|
149
151
|
matchLocation: Pick<MatchLocation, 'to' | 'fuzzy' | 'caseSensitive'>,
|
|
150
152
|
): AnyPathParams | undefined {
|
|
151
|
-
const pathParams = matchByPath(currentPathname, matchLocation)
|
|
153
|
+
const pathParams = matchByPath(basepath, currentPathname, matchLocation)
|
|
152
154
|
// const searchMatched = matchBySearch(currentLocation.search, matchLocation)
|
|
153
155
|
|
|
154
156
|
if (matchLocation.to && !pathParams) {
|
|
@@ -159,11 +161,17 @@ export function matchPathname(
|
|
|
159
161
|
}
|
|
160
162
|
|
|
161
163
|
export function matchByPath(
|
|
164
|
+
basepath: string,
|
|
162
165
|
from: string,
|
|
163
166
|
matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,
|
|
164
167
|
): Record<string, string> | undefined {
|
|
168
|
+
if (basepath && !from.startsWith(basepath)) {
|
|
169
|
+
return undefined
|
|
170
|
+
}
|
|
171
|
+
from = from.startsWith(basepath) ? from.substring(basepath.length) : from
|
|
165
172
|
const baseSegments = parsePathname(from)
|
|
166
|
-
const
|
|
173
|
+
const to = `${matchLocation.to ?? '*'}`
|
|
174
|
+
const routeSegments = parsePathname(to)
|
|
167
175
|
|
|
168
176
|
const params: Record<string, string> = {}
|
|
169
177
|
|
package/src/router.ts
CHANGED
|
@@ -22,6 +22,7 @@ import {
|
|
|
22
22
|
joinPaths,
|
|
23
23
|
matchPathname,
|
|
24
24
|
resolvePath,
|
|
25
|
+
trimPath,
|
|
25
26
|
} from './path'
|
|
26
27
|
import { AnyRoute, createRoute, Route } from './route'
|
|
27
28
|
import {
|
|
@@ -552,9 +553,9 @@ export function createRouter<
|
|
|
552
553
|
|
|
553
554
|
// If the current location isn't updated, trigger a navigation
|
|
554
555
|
// to the current location. Otherwise, load the current location.
|
|
555
|
-
if (next.href !== router.__location.href) {
|
|
556
|
-
|
|
557
|
-
}
|
|
556
|
+
// if (next.href !== router.__location.href) {
|
|
557
|
+
// router.__.commitLocation(next, true)
|
|
558
|
+
// }
|
|
558
559
|
|
|
559
560
|
if (!router.state.matches.length) {
|
|
560
561
|
router.load()
|
|
@@ -600,7 +601,7 @@ export function createRouter<
|
|
|
600
601
|
|
|
601
602
|
const { basepath, routeConfig } = router.options
|
|
602
603
|
|
|
603
|
-
router.basepath =
|
|
604
|
+
router.basepath = `/${trimPath(basepath ?? '') ?? ''}`
|
|
604
605
|
|
|
605
606
|
if (routeConfig) {
|
|
606
607
|
router.routesById = {} as any
|
|
@@ -849,7 +850,7 @@ export function createRouter<
|
|
|
849
850
|
route.routePath !== '/' || route.childRoutes?.length
|
|
850
851
|
)
|
|
851
852
|
|
|
852
|
-
const matchParams = matchPathname(pathname, {
|
|
853
|
+
const matchParams = matchPathname(router.basepath, pathname, {
|
|
853
854
|
to: route.fullPath,
|
|
854
855
|
fuzzy,
|
|
855
856
|
caseSensitive:
|
|
@@ -1031,13 +1032,17 @@ export function createRouter<
|
|
|
1031
1032
|
if (!router.state.pending?.location) {
|
|
1032
1033
|
return false
|
|
1033
1034
|
}
|
|
1034
|
-
return !!matchPathname(
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1035
|
+
return !!matchPathname(
|
|
1036
|
+
router.basepath,
|
|
1037
|
+
router.state.pending.location.pathname,
|
|
1038
|
+
{
|
|
1039
|
+
...opts,
|
|
1040
|
+
to: next.pathname,
|
|
1041
|
+
},
|
|
1042
|
+
)
|
|
1038
1043
|
}
|
|
1039
1044
|
|
|
1040
|
-
return !!matchPathname(router.state.location.pathname, {
|
|
1045
|
+
return !!matchPathname(router.basepath, router.state.location.pathname, {
|
|
1041
1046
|
...opts,
|
|
1042
1047
|
to: next.pathname,
|
|
1043
1048
|
})
|