@tanstack/react-router 1.120.4-alpha.19 → 1.120.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/HeadContent.cjs +6 -23
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/Match.cjs +1 -6
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -2
- package/dist/cjs/RouterProvider.cjs +8 -10
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/Scripts.cjs +1 -2
- package/dist/cjs/Scripts.cjs.map +1 -1
- package/dist/cjs/ScrollRestoration.cjs +2 -2
- package/dist/cjs/ScrollRestoration.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs +0 -8
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +5 -16
- package/dist/cjs/index.d.cts +2 -2
- package/dist/cjs/link.cjs +5 -9
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/router.cjs +0 -8
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/useBlocker.cjs +1 -4
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +7 -14
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/esm/HeadContent.js +6 -23
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Match.js +1 -6
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.d.ts +2 -2
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.js +8 -10
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/Scripts.js +1 -2
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/ScrollRestoration.js +2 -2
- package/dist/esm/ScrollRestoration.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +5 -16
- package/dist/esm/fileRoute.js +0 -8
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/link.js +5 -9
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/router.js +0 -8
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useBlocker.js +1 -4
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useNavigate.js +7 -14
- package/dist/esm/useNavigate.js.map +1 -1
- package/package.json +3 -3
- package/src/HeadContent.tsx +3 -26
- package/src/Match.tsx +4 -15
- package/src/Matches.tsx +1 -4
- package/src/RouterProvider.tsx +9 -11
- package/src/Scripts.tsx +0 -1
- package/src/ScrollRestoration.tsx +1 -1
- package/src/fileRoute.ts +4 -26
- package/src/index.tsx +3 -4
- package/src/link.tsx +4 -18
- package/src/router.ts +0 -9
- package/src/useBlocker.tsx +1 -4
- package/src/useNavigate.tsx +6 -23
package/src/Match.tsx
CHANGED
|
@@ -306,17 +306,6 @@ export const Outlet = React.memo(function OutletImpl() {
|
|
|
306
306
|
},
|
|
307
307
|
})
|
|
308
308
|
|
|
309
|
-
const pendingElement = router.options.defaultPendingComponent ? (
|
|
310
|
-
<router.options.defaultPendingComponent />
|
|
311
|
-
) : null
|
|
312
|
-
|
|
313
|
-
if (router.isShell)
|
|
314
|
-
return (
|
|
315
|
-
<React.Suspense fallback={pendingElement}>
|
|
316
|
-
<ShellInner />
|
|
317
|
-
</React.Suspense>
|
|
318
|
-
)
|
|
319
|
-
|
|
320
309
|
if (parentGlobalNotFound) {
|
|
321
310
|
return renderRouteNotFound(router, route, undefined)
|
|
322
311
|
}
|
|
@@ -327,6 +316,10 @@ export const Outlet = React.memo(function OutletImpl() {
|
|
|
327
316
|
|
|
328
317
|
const nextMatch = <Match matchId={childMatchId} />
|
|
329
318
|
|
|
319
|
+
const pendingElement = router.options.defaultPendingComponent ? (
|
|
320
|
+
<router.options.defaultPendingComponent />
|
|
321
|
+
) : null
|
|
322
|
+
|
|
330
323
|
if (matchId === rootRouteId) {
|
|
331
324
|
return (
|
|
332
325
|
<React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>
|
|
@@ -335,7 +328,3 @@ export const Outlet = React.memo(function OutletImpl() {
|
|
|
335
328
|
|
|
336
329
|
return nextMatch
|
|
337
330
|
})
|
|
338
|
-
|
|
339
|
-
function ShellInner(): React.ReactElement {
|
|
340
|
-
throw new Error('ShellBoundaryError')
|
|
341
|
-
}
|
package/src/Matches.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import type { ReactNode } from './route'
|
|
|
15
15
|
import type {
|
|
16
16
|
AnyRouter,
|
|
17
17
|
DeepPartial,
|
|
18
|
-
Expand,
|
|
19
18
|
MakeOptionalPathParams,
|
|
20
19
|
MakeOptionalSearchParams,
|
|
21
20
|
MakeRouteMatchUnion,
|
|
@@ -124,9 +123,7 @@ export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
|
|
|
124
123
|
const TMaskTo extends string = '',
|
|
125
124
|
>(
|
|
126
125
|
opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
127
|
-
):
|
|
128
|
-
| false
|
|
129
|
-
| Expand<ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']> => {
|
|
126
|
+
): false | ResolveRoute<TRouter, TFrom, TTo>['types']['allParams'] => {
|
|
130
127
|
const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts
|
|
131
128
|
|
|
132
129
|
return router.matchRoute(rest as any, {
|
package/src/RouterProvider.tsx
CHANGED
|
@@ -17,17 +17,15 @@ export function RouterContextProvider<
|
|
|
17
17
|
}: RouterProps<TRouter, TDehydrated> & {
|
|
18
18
|
children: React.ReactNode
|
|
19
19
|
}) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
router.
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
context
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
} as any)
|
|
30
|
-
}
|
|
20
|
+
// Allow the router to update options on the router instance
|
|
21
|
+
router.update({
|
|
22
|
+
...router.options,
|
|
23
|
+
...rest,
|
|
24
|
+
context: {
|
|
25
|
+
...router.options.context,
|
|
26
|
+
...rest.context,
|
|
27
|
+
},
|
|
28
|
+
} as any)
|
|
31
29
|
|
|
32
30
|
const routerContext = getRouterContext()
|
|
33
31
|
|
package/src/Scripts.tsx
CHANGED
package/src/fileRoute.ts
CHANGED
|
@@ -28,7 +28,6 @@ import type {
|
|
|
28
28
|
RouteIds,
|
|
29
29
|
RouteLoaderFn,
|
|
30
30
|
UpdatableRouteOptions,
|
|
31
|
-
UseNavigateResult,
|
|
32
31
|
} from '@tanstack/router-core'
|
|
33
32
|
import type { UseLoaderDepsRoute } from './useLoaderDeps'
|
|
34
33
|
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
@@ -42,13 +41,8 @@ export function createFileRoute<
|
|
|
42
41
|
TFullPath extends
|
|
43
42
|
RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],
|
|
44
43
|
>(
|
|
45
|
-
path
|
|
44
|
+
path: TFilePath,
|
|
46
45
|
): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {
|
|
47
|
-
if (typeof path === 'object') {
|
|
48
|
-
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
|
|
49
|
-
silent: true,
|
|
50
|
-
}).createRoute(path) as any
|
|
51
|
-
}
|
|
52
46
|
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
|
|
53
47
|
silent: true,
|
|
54
48
|
}).createRoute
|
|
@@ -69,7 +63,7 @@ export class FileRoute<
|
|
|
69
63
|
silent?: boolean
|
|
70
64
|
|
|
71
65
|
constructor(
|
|
72
|
-
public path
|
|
66
|
+
public path: TFilePath,
|
|
73
67
|
_opts?: { silent: boolean },
|
|
74
68
|
) {
|
|
75
69
|
this.silent = _opts?.silent
|
|
@@ -165,18 +159,6 @@ export function FileRouteLoader<
|
|
|
165
159
|
return (loaderFn) => loaderFn as any
|
|
166
160
|
}
|
|
167
161
|
|
|
168
|
-
declare module '@tanstack/router-core' {
|
|
169
|
-
export interface LazyRoute<in out TRoute extends AnyRoute> {
|
|
170
|
-
useMatch: UseMatchRoute<TRoute['id']>
|
|
171
|
-
useRouteContext: UseRouteContextRoute<TRoute['id']>
|
|
172
|
-
useSearch: UseSearchRoute<TRoute['id']>
|
|
173
|
-
useParams: UseParamsRoute<TRoute['id']>
|
|
174
|
-
useLoaderDeps: UseLoaderDepsRoute<TRoute['id']>
|
|
175
|
-
useLoaderData: UseLoaderDataRoute<TRoute['id']>
|
|
176
|
-
useNavigate: () => UseNavigateResult<TRoute['fullPath']>
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
162
|
export class LazyRoute<TRoute extends AnyRoute> {
|
|
181
163
|
options: {
|
|
182
164
|
id: string
|
|
@@ -232,7 +214,7 @@ export class LazyRoute<TRoute extends AnyRoute> {
|
|
|
232
214
|
return useLoaderData({ ...opts, from: this.options.id } as any)
|
|
233
215
|
}
|
|
234
216
|
|
|
235
|
-
useNavigate = ()
|
|
217
|
+
useNavigate = () => {
|
|
236
218
|
const router = useRouter()
|
|
237
219
|
return useNavigate({ from: router.routesById[this.options.id].fullPath })
|
|
238
220
|
}
|
|
@@ -254,10 +236,6 @@ export function createLazyRoute<
|
|
|
254
236
|
export function createLazyFileRoute<
|
|
255
237
|
TFilePath extends keyof FileRoutesByPath,
|
|
256
238
|
TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
|
|
257
|
-
>(id: TFilePath)
|
|
258
|
-
if (typeof id === 'object') {
|
|
259
|
-
return new LazyRoute<TRoute>(id) as any
|
|
260
|
-
}
|
|
261
|
-
|
|
239
|
+
>(id: TFilePath) {
|
|
262
240
|
return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })
|
|
263
241
|
}
|
package/src/index.tsx
CHANGED
|
@@ -48,6 +48,7 @@ export type {
|
|
|
48
48
|
DeferredPromiseState,
|
|
49
49
|
DeferredPromise,
|
|
50
50
|
ParsedLocation,
|
|
51
|
+
ParsePathParams,
|
|
51
52
|
RemoveTrailingSlashes,
|
|
52
53
|
RemoveLeadingSlashes,
|
|
53
54
|
ActiveOptions,
|
|
@@ -56,8 +57,6 @@ export type {
|
|
|
56
57
|
RootRouteId,
|
|
57
58
|
AnyPathParams,
|
|
58
59
|
ResolveParams,
|
|
59
|
-
ResolveOptionalParams,
|
|
60
|
-
ResolveRequiredParams,
|
|
61
60
|
SearchSchemaInput,
|
|
62
61
|
AnyContext,
|
|
63
62
|
RouteContext,
|
|
@@ -79,6 +78,8 @@ export type {
|
|
|
79
78
|
TrimPath,
|
|
80
79
|
TrimPathLeft,
|
|
81
80
|
TrimPathRight,
|
|
81
|
+
ParseSplatParams,
|
|
82
|
+
SplatParams,
|
|
82
83
|
StringifyParamsFn,
|
|
83
84
|
ParamsOptions,
|
|
84
85
|
InferAllParams,
|
|
@@ -125,7 +126,6 @@ export type {
|
|
|
125
126
|
RouteById,
|
|
126
127
|
RootRouteOptions,
|
|
127
128
|
SerializerExtensions,
|
|
128
|
-
CreateFileRoute,
|
|
129
129
|
} from '@tanstack/router-core'
|
|
130
130
|
|
|
131
131
|
export type * from './serializer'
|
|
@@ -237,7 +237,6 @@ export type {
|
|
|
237
237
|
RouteConstraints,
|
|
238
238
|
RouteMask,
|
|
239
239
|
MatchRouteOptions,
|
|
240
|
-
CreateLazyFileRoute,
|
|
241
240
|
} from '@tanstack/router-core'
|
|
242
241
|
export type {
|
|
243
242
|
UseLinkPropsOptions,
|
package/src/link.tsx
CHANGED
|
@@ -16,7 +16,6 @@ import {
|
|
|
16
16
|
useLayoutEffect,
|
|
17
17
|
} from './utils'
|
|
18
18
|
|
|
19
|
-
import { useMatch } from './useMatch'
|
|
20
19
|
import { useMatches } from './Matches'
|
|
21
20
|
import type {
|
|
22
21
|
AnyRouter,
|
|
@@ -106,24 +105,11 @@ export function useLinkProps<
|
|
|
106
105
|
structuralSharing: true as any,
|
|
107
106
|
})
|
|
108
107
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
const nearestFrom = useMatch({
|
|
114
|
-
strict: false,
|
|
115
|
-
select: (match) => (isRelativeFromPath ? undefined : match.fullPath),
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
// When no from and relative is path, use the leaf match as the from location
|
|
119
|
-
// Avoid rerenders as much as possible.
|
|
120
|
-
const leafFrom = useMatches({
|
|
121
|
-
select: (matches) =>
|
|
122
|
-
isRelativeFromPath ? matches[matches.length - 1]!.fullPath : undefined,
|
|
108
|
+
// when `from` is not supplied, use the leaf route of the current matches as the `from` location
|
|
109
|
+
// so relative routing works as expected
|
|
110
|
+
const from = useMatches({
|
|
111
|
+
select: (matches) => options.from ?? matches[matches.length - 1]?.fullPath,
|
|
123
112
|
})
|
|
124
|
-
|
|
125
|
-
const from = options.from ?? (isRelativeFromPath ? leafFrom : nearestFrom)
|
|
126
|
-
|
|
127
113
|
// Use it as the default `from` location
|
|
128
114
|
const _options = React.useMemo(() => ({ ...options, from }), [options, from])
|
|
129
115
|
|
package/src/router.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { RouterCore } from '@tanstack/router-core'
|
|
2
|
-
import { createFileRoute, createLazyFileRoute } from './fileRoute'
|
|
3
2
|
import type { RouterHistory } from '@tanstack/history'
|
|
4
3
|
import type {
|
|
5
4
|
AnyRoute,
|
|
@@ -106,11 +105,3 @@ export class Router<
|
|
|
106
105
|
super(options)
|
|
107
106
|
}
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
if (typeof globalThis !== 'undefined') {
|
|
111
|
-
;(globalThis as any).createFileRoute = createFileRoute
|
|
112
|
-
;(globalThis as any).createLazyFileRoute = createLazyFileRoute
|
|
113
|
-
} else if (typeof window !== 'undefined') {
|
|
114
|
-
;(window as any).createFileRoute = createFileRoute
|
|
115
|
-
;(window as any).createFileRoute = createLazyFileRoute
|
|
116
|
-
}
|
package/src/useBlocker.tsx
CHANGED
|
@@ -177,10 +177,7 @@ export function useBlocker(
|
|
|
177
177
|
location: HistoryLocation,
|
|
178
178
|
): AnyShouldBlockFnLocation {
|
|
179
179
|
const parsedLocation = router.parseLocation(undefined, location)
|
|
180
|
-
const matchedRoutes = router.getMatchedRoutes(
|
|
181
|
-
parsedLocation.pathname,
|
|
182
|
-
undefined,
|
|
183
|
-
)
|
|
180
|
+
const matchedRoutes = router.getMatchedRoutes(parsedLocation)
|
|
184
181
|
if (matchedRoutes.foundRoute === undefined) {
|
|
185
182
|
throw new Error(`No route found for location ${location.href}`)
|
|
186
183
|
}
|
package/src/useNavigate.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { useRouter } from './useRouter'
|
|
3
|
-
import { useMatch } from './useMatch'
|
|
4
3
|
import type {
|
|
5
4
|
AnyRouter,
|
|
6
5
|
FromPathOption,
|
|
@@ -15,32 +14,15 @@ export function useNavigate<
|
|
|
15
14
|
>(_defaultOpts?: {
|
|
16
15
|
from?: FromPathOption<TRouter, TDefaultFrom>
|
|
17
16
|
}): UseNavigateResult<TDefaultFrom> {
|
|
18
|
-
const { navigate
|
|
19
|
-
|
|
20
|
-
// Just get the index of the current match to avoid rerenders
|
|
21
|
-
// as much as possible
|
|
22
|
-
const matchIndex = useMatch({
|
|
23
|
-
strict: false,
|
|
24
|
-
select: (match) => match.index,
|
|
25
|
-
})
|
|
17
|
+
const { navigate } = useRouter()
|
|
26
18
|
|
|
27
19
|
return React.useCallback(
|
|
28
20
|
(options: NavigateOptions) => {
|
|
29
|
-
const isRelativeFromPath = options.relative === 'path'
|
|
30
|
-
|
|
31
|
-
const from =
|
|
32
|
-
options.from ??
|
|
33
|
-
_defaultOpts?.from ??
|
|
34
|
-
(isRelativeFromPath
|
|
35
|
-
? state.matches[state.matches.length - 1]!.fullPath
|
|
36
|
-
: state.matches[matchIndex]!.fullPath)
|
|
37
|
-
|
|
38
21
|
return navigate({
|
|
22
|
+
from: _defaultOpts?.from,
|
|
39
23
|
...options,
|
|
40
|
-
from: from,
|
|
41
24
|
})
|
|
42
25
|
},
|
|
43
|
-
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
44
26
|
[_defaultOpts?.from, navigate],
|
|
45
27
|
) as UseNavigateResult<TDefaultFrom>
|
|
46
28
|
}
|
|
@@ -53,7 +35,6 @@ export function Navigate<
|
|
|
53
35
|
const TMaskTo extends string = '',
|
|
54
36
|
>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {
|
|
55
37
|
const router = useRouter()
|
|
56
|
-
const navigate = useNavigate()
|
|
57
38
|
|
|
58
39
|
const previousPropsRef = React.useRef<NavigateOptions<
|
|
59
40
|
TRouter,
|
|
@@ -64,9 +45,11 @@ export function Navigate<
|
|
|
64
45
|
> | null>(null)
|
|
65
46
|
React.useEffect(() => {
|
|
66
47
|
if (previousPropsRef.current !== props) {
|
|
67
|
-
navigate(
|
|
48
|
+
router.navigate({
|
|
49
|
+
...props,
|
|
50
|
+
})
|
|
68
51
|
previousPropsRef.current = props
|
|
69
52
|
}
|
|
70
|
-
}, [router, props
|
|
53
|
+
}, [router, props])
|
|
71
54
|
return null
|
|
72
55
|
}
|