@tanstack/router-core 0.0.1-beta.31 → 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.31",
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 {
@@ -246,8 +247,9 @@ export interface MatchLocation {
246
247
  }
247
248
 
248
249
  export interface MatchRouteOptions {
249
- pending: boolean
250
+ pending?: boolean
250
251
  caseSensitive?: boolean
252
+ fuzzy?: boolean
251
253
  }
252
254
 
253
255
  type LinkCurrentTargetElement = {
@@ -551,9 +553,9 @@ export function createRouter<
551
553
 
552
554
  // If the current location isn't updated, trigger a navigation
553
555
  // to the current location. Otherwise, load the current location.
554
- if (next.href !== router.__location.href) {
555
- router.__.commitLocation(next, true)
556
- }
556
+ // if (next.href !== router.__location.href) {
557
+ // router.__.commitLocation(next, true)
558
+ // }
557
559
 
558
560
  if (!router.state.matches.length) {
559
561
  router.load()
@@ -599,7 +601,7 @@ export function createRouter<
599
601
 
600
602
  const { basepath, routeConfig } = router.options
601
603
 
602
- router.basepath = cleanPath(`/${basepath ?? ''}`)
604
+ router.basepath = `/${trimPath(basepath ?? '') ?? ''}`
603
605
 
604
606
  if (routeConfig) {
605
607
  router.routesById = {} as any
@@ -848,7 +850,7 @@ export function createRouter<
848
850
  route.routePath !== '/' || route.childRoutes?.length
849
851
  )
850
852
 
851
- const matchParams = matchPathname(pathname, {
853
+ const matchParams = matchPathname(router.basepath, pathname, {
852
854
  to: route.fullPath,
853
855
  fuzzy,
854
856
  caseSensitive:
@@ -924,15 +926,16 @@ export function createRouter<
924
926
  const matchPromises = resolvedMatches.map(async (match) => {
925
927
  // Validate the match (loads search params etc)
926
928
  match.__.validate()
927
- match.load(loaderOpts)
928
929
 
929
930
  const search = match.search as { __data?: any }
930
931
 
931
- if (search.__data && search.__data.matchId !== match.matchId) {
932
+ if (search.__data?.matchId && search.__data.matchId !== match.matchId) {
932
933
  return
933
934
  }
934
935
 
935
- if (match.__.loadPromise) {
936
+ match.load(loaderOpts)
937
+
938
+ if (match.status !== 'success' && match.__.loadPromise) {
936
939
  // Wait for the first sign of activity from the match
937
940
  await match.__.loadPromise
938
941
  }
@@ -1029,13 +1032,17 @@ export function createRouter<
1029
1032
  if (!router.state.pending?.location) {
1030
1033
  return false
1031
1034
  }
1032
- return !!matchPathname(router.state.pending.location.pathname, {
1033
- ...opts,
1034
- to: next.pathname,
1035
- })
1035
+ return !!matchPathname(
1036
+ router.basepath,
1037
+ router.state.pending.location.pathname,
1038
+ {
1039
+ ...opts,
1040
+ to: next.pathname,
1041
+ },
1042
+ )
1036
1043
  }
1037
1044
 
1038
- return !!matchPathname(router.state.location.pathname, {
1045
+ return !!matchPathname(router.basepath, router.state.location.pathname, {
1039
1046
  ...opts,
1040
1047
  to: next.pathname,
1041
1048
  })