@tanstack/react-router 1.44.5 → 1.45.2
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/Match.cjs.map +1 -1
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/path.cjs +1 -1
- package/dist/cjs/path.cjs.map +1 -1
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/useMatch.cjs +4 -1
- package/dist/cjs/useMatch.cjs.map +1 -1
- package/dist/cjs/useMatch.d.cts +3 -2
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/path.js +1 -1
- package/dist/esm/path.js.map +1 -1
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useMatch.d.ts +3 -2
- package/dist/esm/useMatch.js +4 -1
- package/dist/esm/useMatch.js.map +1 -1
- package/package.json +1 -1
- package/src/Match.tsx +2 -2
- package/src/link.tsx +2 -2
- package/src/path.ts +1 -1
- package/src/router.ts +9 -7
- package/src/useMatch.tsx +11 -3
package/package.json
CHANGED
package/src/Match.tsx
CHANGED
|
@@ -41,8 +41,8 @@ export function Match({ matchId }: { matchId: string }) {
|
|
|
41
41
|
|
|
42
42
|
const routeNotFoundComponent = route.isRoot
|
|
43
43
|
? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
|
|
44
|
-
route.options.notFoundComponent ??
|
|
45
|
-
router.options.notFoundRoute?.options.component
|
|
44
|
+
(route.options.notFoundComponent ??
|
|
45
|
+
router.options.notFoundRoute?.options.component)
|
|
46
46
|
: route.options.notFoundComponent
|
|
47
47
|
|
|
48
48
|
const ResolvedSuspenseBoundary =
|
package/src/link.tsx
CHANGED
|
@@ -619,7 +619,7 @@ export function useLinkProps<
|
|
|
619
619
|
? s.location.hash === next.hash
|
|
620
620
|
: true
|
|
621
621
|
const searchTest =
|
|
622
|
-
activeOptions?.includeSearch ?? true
|
|
622
|
+
(activeOptions?.includeSearch ?? true)
|
|
623
623
|
? deepEqual(s.location.search, next.search, !activeOptions?.exact)
|
|
624
624
|
: true
|
|
625
625
|
|
|
@@ -733,7 +733,7 @@ export function useLinkProps<
|
|
|
733
733
|
|
|
734
734
|
// Get the active props
|
|
735
735
|
const resolvedActiveProps: React.HTMLAttributes<HTMLAnchorElement> = isActive
|
|
736
|
-
? functionalUpdate(activeProps as any, {}) ?? {}
|
|
736
|
+
? (functionalUpdate(activeProps as any, {}) ?? {})
|
|
737
737
|
: {}
|
|
738
738
|
|
|
739
739
|
// Get the inactive props
|
package/src/path.ts
CHANGED
package/src/router.ts
CHANGED
|
@@ -1855,7 +1855,8 @@ export class Router<
|
|
|
1855
1855
|
}
|
|
1856
1856
|
|
|
1857
1857
|
const beforeLoadContext = route.options.beforeLoad
|
|
1858
|
-
? (await route.options.beforeLoad(beforeLoadFnContext)) ??
|
|
1858
|
+
? ((await route.options.beforeLoad(beforeLoadFnContext)) ??
|
|
1859
|
+
{})
|
|
1859
1860
|
: {}
|
|
1860
1861
|
|
|
1861
1862
|
checkLatest()
|
|
@@ -2068,12 +2069,12 @@ export class Router<
|
|
|
2068
2069
|
const age = Date.now() - match.updatedAt
|
|
2069
2070
|
|
|
2070
2071
|
const staleAge = preload
|
|
2071
|
-
? route.options.preloadStaleTime ??
|
|
2072
|
+
? (route.options.preloadStaleTime ??
|
|
2072
2073
|
this.options.defaultPreloadStaleTime ??
|
|
2073
|
-
30_000 // 30 seconds for preloads by default
|
|
2074
|
-
: route.options.staleTime ??
|
|
2074
|
+
30_000) // 30 seconds for preloads by default
|
|
2075
|
+
: (route.options.staleTime ??
|
|
2075
2076
|
this.options.defaultStaleTime ??
|
|
2076
|
-
0
|
|
2077
|
+
0)
|
|
2077
2078
|
|
|
2078
2079
|
const shouldReloadOption = route.options.shouldReload
|
|
2079
2080
|
|
|
@@ -2190,8 +2191,9 @@ export class Router<
|
|
|
2190
2191
|
// otherwise, use the gcTime
|
|
2191
2192
|
const gcTime =
|
|
2192
2193
|
(d.preload
|
|
2193
|
-
? route.options.preloadGcTime ??
|
|
2194
|
-
|
|
2194
|
+
? (route.options.preloadGcTime ??
|
|
2195
|
+
this.options.defaultPreloadGcTime)
|
|
2196
|
+
: (route.options.gcTime ?? this.options.defaultGcTime)) ??
|
|
2195
2197
|
5 * 60 * 1000
|
|
2196
2198
|
|
|
2197
2199
|
return d.status !== 'error' && Date.now() - d.updatedAt < gcTime
|
package/src/useMatch.tsx
CHANGED
|
@@ -13,8 +13,10 @@ export type UseMatchOptions<
|
|
|
13
13
|
TStrict extends boolean,
|
|
14
14
|
TRouteMatch,
|
|
15
15
|
TSelected,
|
|
16
|
+
TThrow extends boolean,
|
|
16
17
|
> = StrictOrFrom<TFrom, TStrict> & {
|
|
17
18
|
select?: (match: TRouteMatch) => TSelected
|
|
19
|
+
shouldThrow?: TThrow
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
export function useMatch<
|
|
@@ -23,7 +25,10 @@ export function useMatch<
|
|
|
23
25
|
TStrict extends boolean = true,
|
|
24
26
|
TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TStrict>,
|
|
25
27
|
TSelected = TRouteMatch,
|
|
26
|
-
|
|
28
|
+
TThrow extends boolean = true,
|
|
29
|
+
>(
|
|
30
|
+
opts: UseMatchOptions<TFrom, TStrict, TRouteMatch, TSelected, TThrow>,
|
|
31
|
+
): TThrow extends true ? TSelected : TSelected | undefined {
|
|
27
32
|
const nearestMatchId = React.useContext(matchContext)
|
|
28
33
|
|
|
29
34
|
const matchSelection = useRouterState({
|
|
@@ -31,12 +36,15 @@ export function useMatch<
|
|
|
31
36
|
const match = state.matches.find((d) =>
|
|
32
37
|
opts.from ? opts.from === d.routeId : d.id === nearestMatchId,
|
|
33
38
|
)
|
|
34
|
-
|
|
35
39
|
invariant(
|
|
36
|
-
match,
|
|
40
|
+
!((opts.shouldThrow ?? true) && !match),
|
|
37
41
|
`Could not find ${opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`,
|
|
38
42
|
)
|
|
39
43
|
|
|
44
|
+
if (match === undefined) {
|
|
45
|
+
return undefined
|
|
46
|
+
}
|
|
47
|
+
|
|
40
48
|
return opts.select ? opts.select(match as any) : match
|
|
41
49
|
},
|
|
42
50
|
})
|