@tanstack/react-router 1.63.1 → 1.63.4
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/path.cjs +3 -0
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +5 -4
- package/dist/cjs/router.cjs +25 -25
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -0
- package/dist/esm/path.js +3 -0
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/route.d.ts +5 -4
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +1 -0
- package/dist/esm/router.js +25 -25
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/path.ts +4 -0
- package/src/route.ts +8 -7
- package/src/router.ts +39 -38
package/package.json
CHANGED
package/src/path.ts
CHANGED
|
@@ -298,6 +298,10 @@ export function matchByPath(
|
|
|
298
298
|
from: string,
|
|
299
299
|
matchLocation: Pick<MatchLocation, 'to' | 'caseSensitive' | 'fuzzy'>,
|
|
300
300
|
): Record<string, string> | undefined {
|
|
301
|
+
// check basepath first
|
|
302
|
+
if (basepath !== '/' && !from.startsWith(basepath)) {
|
|
303
|
+
return undefined
|
|
304
|
+
}
|
|
301
305
|
// Remove the base path from the pathname
|
|
302
306
|
from = removeBasepath(basepath, from)
|
|
303
307
|
// Default to to $ (wildcard)
|
package/src/route.ts
CHANGED
|
@@ -201,9 +201,9 @@ export type FileBaseRouteOptions<
|
|
|
201
201
|
(
|
|
202
202
|
ctx: RouteContextOptions<
|
|
203
203
|
TParentRoute,
|
|
204
|
-
TSearchValidator,
|
|
205
204
|
TParams,
|
|
206
|
-
TRouterContext
|
|
205
|
+
TRouterContext,
|
|
206
|
+
TLoaderDeps
|
|
207
207
|
>,
|
|
208
208
|
) => any
|
|
209
209
|
>
|
|
@@ -272,9 +272,8 @@ export type BaseRouteOptions<
|
|
|
272
272
|
|
|
273
273
|
export interface ContextOptions<
|
|
274
274
|
in out TParentRoute extends AnyRoute,
|
|
275
|
-
in out TSearchValidator,
|
|
276
275
|
in out TParams,
|
|
277
|
-
>
|
|
276
|
+
> {
|
|
278
277
|
abortController: AbortController
|
|
279
278
|
preload: boolean
|
|
280
279
|
params: Expand<ResolveAllParamsFromParent<TParentRoute, TParams>>
|
|
@@ -290,10 +289,11 @@ export interface ContextOptions<
|
|
|
290
289
|
|
|
291
290
|
export interface RouteContextOptions<
|
|
292
291
|
in out TParentRoute extends AnyRoute,
|
|
293
|
-
in out TSearchValidator,
|
|
294
292
|
in out TParams,
|
|
295
293
|
in out TRouterContext,
|
|
296
|
-
|
|
294
|
+
in out TLoaderDeps,
|
|
295
|
+
> extends ContextOptions<TParentRoute, TParams> {
|
|
296
|
+
deps: TLoaderDeps
|
|
297
297
|
context: Expand<RouteContextParameter<TParentRoute, TRouterContext>>
|
|
298
298
|
}
|
|
299
299
|
|
|
@@ -303,7 +303,8 @@ export interface BeforeLoadContextOptions<
|
|
|
303
303
|
in out TParams,
|
|
304
304
|
in out TRouterContext,
|
|
305
305
|
in out TRouteContextFn,
|
|
306
|
-
> extends ContextOptions<TParentRoute,
|
|
306
|
+
> extends ContextOptions<TParentRoute, TParams>,
|
|
307
|
+
FullSearchSchemaOption<TParentRoute, TSearchValidator> {
|
|
307
308
|
context: Expand<
|
|
308
309
|
BeforeLoadContextParameter<TParentRoute, TRouterContext, TRouteContextFn>
|
|
309
310
|
>
|
package/src/router.ts
CHANGED
|
@@ -82,8 +82,6 @@ import type { NotFoundError } from './not-found'
|
|
|
82
82
|
import type { NavigateOptions, ResolveRelativePath, ToOptions } from './link'
|
|
83
83
|
import type { RouterTransformer } from './transformer'
|
|
84
84
|
|
|
85
|
-
//
|
|
86
|
-
|
|
87
85
|
declare global {
|
|
88
86
|
interface Window {
|
|
89
87
|
__TSR__?: {
|
|
@@ -600,7 +598,11 @@ export function createRouter<
|
|
|
600
598
|
>(options)
|
|
601
599
|
}
|
|
602
600
|
|
|
603
|
-
type MatchRoutesOpts = {
|
|
601
|
+
type MatchRoutesOpts = {
|
|
602
|
+
preload?: boolean
|
|
603
|
+
throwOnError?: boolean
|
|
604
|
+
_buildLocation?: boolean
|
|
605
|
+
}
|
|
604
606
|
|
|
605
607
|
export class Router<
|
|
606
608
|
in out TRouteTree extends AnyRoute,
|
|
@@ -991,10 +993,8 @@ export class Router<
|
|
|
991
993
|
|
|
992
994
|
public matchRoutes(
|
|
993
995
|
pathnameOrNext: string | ParsedLocation,
|
|
994
|
-
locationSearchOrOpts?:
|
|
995
|
-
|
|
996
|
-
| { preload?: boolean; throwOnError?: boolean },
|
|
997
|
-
opts?: { preload?: boolean; throwOnError?: boolean },
|
|
996
|
+
locationSearchOrOpts?: AnySearchSchema | MatchRoutesOpts,
|
|
997
|
+
opts?: MatchRoutesOpts,
|
|
998
998
|
) {
|
|
999
999
|
if (typeof pathnameOrNext === 'string') {
|
|
1000
1000
|
return this.matchRoutesInternal(
|
|
@@ -1011,7 +1011,7 @@ export class Router<
|
|
|
1011
1011
|
|
|
1012
1012
|
private matchRoutesInternal(
|
|
1013
1013
|
next: ParsedLocation,
|
|
1014
|
-
opts?:
|
|
1014
|
+
opts?: MatchRoutesOpts,
|
|
1015
1015
|
): Array<AnyRouteMatch> {
|
|
1016
1016
|
let routeParams: Record<string, string> = {}
|
|
1017
1017
|
|
|
@@ -1081,9 +1081,6 @@ export class Router<
|
|
|
1081
1081
|
return rootRouteId
|
|
1082
1082
|
})()
|
|
1083
1083
|
|
|
1084
|
-
// Existing matches are matches that are already loaded along with
|
|
1085
|
-
// pending matches that are still loading
|
|
1086
|
-
|
|
1087
1084
|
const parseErrors = matchedRoutes.map((route) => {
|
|
1088
1085
|
let parsedParamsError
|
|
1089
1086
|
|
|
@@ -1182,6 +1179,9 @@ export class Router<
|
|
|
1182
1179
|
// Waste not, want not. If we already have a match for this route,
|
|
1183
1180
|
// reuse it. This is important for layout routes, which might stick
|
|
1184
1181
|
// around between navigation actions that only change leaf routes.
|
|
1182
|
+
|
|
1183
|
+
// Existing matches are matches that are already loaded along with
|
|
1184
|
+
// pending matches that are still loading
|
|
1185
1185
|
const existingMatch = this.getMatch(matchId)
|
|
1186
1186
|
|
|
1187
1187
|
const cause = this.state.matches.find((d) => d.id === matchId)
|
|
@@ -1274,28 +1274,31 @@ export class Router<
|
|
|
1274
1274
|
...match.__beforeLoadContext,
|
|
1275
1275
|
}
|
|
1276
1276
|
|
|
1277
|
-
//
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1285
|
-
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1277
|
+
// only execute `context` if we are not just building a location
|
|
1278
|
+
if (!existingMatch && opts?._buildLocation !== true) {
|
|
1279
|
+
// Update the match's context
|
|
1280
|
+
const contextFnContext: RouteContextOptions<any, any, any, any> = {
|
|
1281
|
+
deps: loaderDeps,
|
|
1282
|
+
params: match.params,
|
|
1283
|
+
context: match.context,
|
|
1284
|
+
location: next,
|
|
1285
|
+
navigate: (opts: any) =>
|
|
1286
|
+
this.navigate({ ...opts, _fromLocation: next }),
|
|
1287
|
+
buildLocation: this.buildLocation,
|
|
1288
|
+
cause: match.cause,
|
|
1289
|
+
abortController: match.abortController,
|
|
1290
|
+
preload: !!match.preload,
|
|
1291
|
+
matches,
|
|
1292
|
+
}
|
|
1291
1293
|
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
+
// Get the route context
|
|
1295
|
+
match.__routeContext = route.options.context?.(contextFnContext) ?? {}
|
|
1294
1296
|
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1297
|
+
match.context = {
|
|
1298
|
+
...parentContext,
|
|
1299
|
+
...match.__routeContext,
|
|
1300
|
+
...match.__beforeLoadContext,
|
|
1301
|
+
}
|
|
1299
1302
|
}
|
|
1300
1303
|
|
|
1301
1304
|
matches.push(match)
|
|
@@ -1327,7 +1330,7 @@ export class Router<
|
|
|
1327
1330
|
matches?: Array<MakeRouteMatch<TRouteTree>>,
|
|
1328
1331
|
): ParsedLocation => {
|
|
1329
1332
|
const fromMatches = dest._fromLocation
|
|
1330
|
-
? this.matchRoutes(dest._fromLocation)
|
|
1333
|
+
? this.matchRoutes(dest._fromLocation, { _buildLocation: true })
|
|
1331
1334
|
: this.state.matches
|
|
1332
1335
|
|
|
1333
1336
|
const fromMatch =
|
|
@@ -1506,9 +1509,9 @@ export class Router<
|
|
|
1506
1509
|
}
|
|
1507
1510
|
}
|
|
1508
1511
|
|
|
1509
|
-
const nextMatches = this.matchRoutes(next)
|
|
1512
|
+
const nextMatches = this.matchRoutes(next, { _buildLocation: true })
|
|
1510
1513
|
const maskedMatches = maskedNext
|
|
1511
|
-
? this.matchRoutes(maskedNext)
|
|
1514
|
+
? this.matchRoutes(maskedNext, { _buildLocation: true })
|
|
1512
1515
|
: undefined
|
|
1513
1516
|
const maskedFinal = maskedNext
|
|
1514
1517
|
? build(maskedDest, maskedMatches)
|
|
@@ -2254,10 +2257,8 @@ export class Router<
|
|
|
2254
2257
|
route._lazyPromise ||
|
|
2255
2258
|
(route.lazyFn
|
|
2256
2259
|
? route.lazyFn().then((lazyRoute) => {
|
|
2257
|
-
|
|
2258
|
-
|
|
2259
|
-
lazyRoute.options,
|
|
2260
|
-
)
|
|
2260
|
+
const { id, ...options } = lazyRoute.options
|
|
2261
|
+
Object.assign(route.options, options)
|
|
2261
2262
|
})
|
|
2262
2263
|
: Promise.resolve())
|
|
2263
2264
|
|