@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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/router-core",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.33",
4
+ "version": "0.0.1-beta.34",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
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 routeSegments = parsePathname(`${matchLocation.to ?? '*'}`)
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
- router.__.commitLocation(next, true)
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 = cleanPath(`/${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(router.state.pending.location.pathname, {
1035
- ...opts,
1036
- to: next.pathname,
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
  })