@tanstack/react-router 1.26.17 → 1.26.19
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/link.cjs.map +1 -1
- package/dist/cjs/link.d.cts +2 -2
- package/dist/cjs/router.cjs +6 -0
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/esm/link.d.ts +2 -2
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.js +7 -1
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/link.tsx +26 -9
- package/src/router.ts +17 -0
package/package.json
CHANGED
package/src/link.tsx
CHANGED
|
@@ -87,7 +87,9 @@ export type RemoveLeadingSlashes<T> = T extends `/${infer R}`
|
|
|
87
87
|
export type SearchPaths<
|
|
88
88
|
TPaths,
|
|
89
89
|
TSearchPath extends string,
|
|
90
|
-
> = TPaths extends `${TSearchPath}/${infer TRest}`
|
|
90
|
+
> = TPaths extends `${RemoveTrailingSlashes<TSearchPath>}/${infer TRest}`
|
|
91
|
+
? TRest
|
|
92
|
+
: never
|
|
91
93
|
|
|
92
94
|
export type SearchRelativePathAutoComplete<
|
|
93
95
|
TTo extends string,
|
|
@@ -121,16 +123,12 @@ export type AbsolutePathAutoComplete<TFrom extends string, TPaths> =
|
|
|
121
123
|
? './'
|
|
122
124
|
: TFrom extends `/`
|
|
123
125
|
? never
|
|
124
|
-
: SearchPaths<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
> extends infer SearchedPaths
|
|
128
|
-
? SearchedPaths extends ''
|
|
129
|
-
? never
|
|
130
|
-
: './'
|
|
131
|
-
: never)
|
|
126
|
+
: SearchPaths<TPaths, TFrom> extends ''
|
|
127
|
+
? never
|
|
128
|
+
: './')
|
|
132
129
|
| (string extends TFrom ? '../' : TFrom extends `/` ? never : '../')
|
|
133
130
|
| TPaths
|
|
131
|
+
| (TFrom extends '/' ? never : SearchPaths<TPaths, TFrom>)
|
|
134
132
|
|
|
135
133
|
export type RelativeToPathAutoComplete<
|
|
136
134
|
TRouteTree extends AnyRoute,
|
|
@@ -352,6 +350,25 @@ export type ResolveRelativePath<TFrom, TTo = '.'> = TFrom extends string
|
|
|
352
350
|
: never
|
|
353
351
|
: never
|
|
354
352
|
|
|
353
|
+
// type Test1 = ResolveRelativePath<'/', '/posts'>
|
|
354
|
+
// // ^?
|
|
355
|
+
// type Test4 = ResolveRelativePath<'/posts/1/comments', '../..'>
|
|
356
|
+
// // ^?
|
|
357
|
+
// type Test5 = ResolveRelativePath<'/posts/1/comments', '../../..'>
|
|
358
|
+
// // ^?
|
|
359
|
+
// type Test6 = ResolveRelativePath<'/posts/1/comments', './1'>
|
|
360
|
+
// // ^?
|
|
361
|
+
// type Test7 = ResolveRelativePath<'/posts/1/comments', './1/2'>
|
|
362
|
+
// // ^?
|
|
363
|
+
// type Test8 = ResolveRelativePath<'/posts/1/comments', '../edit'>
|
|
364
|
+
// // ^?
|
|
365
|
+
// type Test9 = ResolveRelativePath<'/posts/1/comments', '1'>
|
|
366
|
+
// // ^?
|
|
367
|
+
// type Test10 = ResolveRelativePath<'/posts/1/comments', './1'>
|
|
368
|
+
// // ^?
|
|
369
|
+
// type Test11 = ResolveRelativePath<'/posts/1/comments', './1/2'>
|
|
370
|
+
// // ^?
|
|
371
|
+
|
|
355
372
|
type LinkCurrentTargetElement = {
|
|
356
373
|
preloadTimeout?: null | ReturnType<typeof setTimeout>
|
|
357
374
|
}
|
package/src/router.ts
CHANGED
|
@@ -1777,6 +1777,23 @@ export class Router<
|
|
|
1777
1777
|
})
|
|
1778
1778
|
})
|
|
1779
1779
|
|
|
1780
|
+
// If the preload leaf match is the same as the current or pending leaf match,
|
|
1781
|
+
// do not preload as it could cause a mutation of the current route.
|
|
1782
|
+
// The user should specify proper loaderDeps (which are used to uniquely identify a route)
|
|
1783
|
+
// to trigger preloads for routes with the same pathname, but different deps
|
|
1784
|
+
|
|
1785
|
+
const leafMatch = last(matches)
|
|
1786
|
+
const currentLeafMatch = last(this.state.matches)
|
|
1787
|
+
const pendingLeafMatch = last(this.state.pendingMatches ?? [])
|
|
1788
|
+
|
|
1789
|
+
if (
|
|
1790
|
+
leafMatch &&
|
|
1791
|
+
(currentLeafMatch?.id === leafMatch.id ||
|
|
1792
|
+
pendingLeafMatch?.id === leafMatch.id)
|
|
1793
|
+
) {
|
|
1794
|
+
return undefined
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1780
1797
|
try {
|
|
1781
1798
|
matches = await this.loadMatches({
|
|
1782
1799
|
matches,
|