@tanstack/solid-router 1.120.3 → 1.120.4-alpha.10
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 +18 -6
- package/dist/cjs/HeadContent.cjs.map +1 -1
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -2
- package/dist/cjs/fileRoute.cjs +8 -0
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +16 -5
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/router.cjs +8 -0
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/useBlocker.cjs +1 -1
- package/dist/cjs/useBlocker.cjs.map +1 -1
- package/dist/esm/HeadContent.js +18 -6
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Matches.d.ts +2 -2
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +16 -5
- package/dist/esm/fileRoute.js +8 -0
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/router.js +8 -0
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useBlocker.js +1 -1
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/source/HeadContent.jsx +25 -10
- package/dist/source/HeadContent.jsx.map +1 -1
- package/dist/source/Matches.d.ts +2 -2
- package/dist/source/Matches.jsx.map +1 -1
- package/dist/source/fileRoute.d.ts +16 -5
- package/dist/source/fileRoute.js +8 -0
- package/dist/source/fileRoute.js.map +1 -1
- package/dist/source/index.d.ts +1 -1
- package/dist/source/index.jsx.map +1 -1
- package/dist/source/router.js +11 -0
- package/dist/source/router.js.map +1 -1
- package/dist/source/useBlocker.jsx +1 -1
- package/dist/source/useBlocker.jsx.map +1 -1
- package/package.json +3 -3
- package/src/HeadContent.tsx +23 -3
- package/src/Matches.tsx +2 -1
- package/src/fileRoute.ts +26 -4
- package/src/index.tsx +4 -3
- package/src/router.ts +9 -0
- package/src/useBlocker.tsx +4 -1
package/src/HeadContent.tsx
CHANGED
|
@@ -59,8 +59,8 @@ export const useTags = () => {
|
|
|
59
59
|
})
|
|
60
60
|
|
|
61
61
|
const links = useRouterState({
|
|
62
|
-
select: (state) =>
|
|
63
|
-
state.matches
|
|
62
|
+
select: (state) => {
|
|
63
|
+
const constructed = state.matches
|
|
64
64
|
.map((match) => match.links!)
|
|
65
65
|
.filter(Boolean)
|
|
66
66
|
.flat(1)
|
|
@@ -69,7 +69,27 @@ export const useTags = () => {
|
|
|
69
69
|
attrs: {
|
|
70
70
|
...link,
|
|
71
71
|
},
|
|
72
|
-
}))
|
|
72
|
+
})) satisfies Array<RouterManagedTag>
|
|
73
|
+
|
|
74
|
+
const manifest = router.ssr?.manifest
|
|
75
|
+
|
|
76
|
+
// These are the assets extracted from the ViteManifest
|
|
77
|
+
// using the `startManifestPlugin`
|
|
78
|
+
const assets = state.matches
|
|
79
|
+
.map((match) => manifest?.routes[match.routeId]?.assets ?? [])
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.flat(1)
|
|
82
|
+
.filter((asset) => asset.tag === 'link')
|
|
83
|
+
.map(
|
|
84
|
+
(asset) =>
|
|
85
|
+
({
|
|
86
|
+
tag: 'link',
|
|
87
|
+
attrs: asset.attrs,
|
|
88
|
+
}) satisfies RouterManagedTag,
|
|
89
|
+
)
|
|
90
|
+
|
|
91
|
+
return [...constructed, ...assets]
|
|
92
|
+
},
|
|
73
93
|
})
|
|
74
94
|
|
|
75
95
|
const preloadMeta = useRouterState({
|
package/src/Matches.tsx
CHANGED
|
@@ -10,6 +10,7 @@ import { SafeFragment } from './SafeFragment'
|
|
|
10
10
|
import type {
|
|
11
11
|
AnyRouter,
|
|
12
12
|
DeepPartial,
|
|
13
|
+
Expand,
|
|
13
14
|
MakeOptionalPathParams,
|
|
14
15
|
MakeOptionalSearchParams,
|
|
15
16
|
MakeRouteMatchUnion,
|
|
@@ -117,7 +118,7 @@ export function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>() {
|
|
|
117
118
|
>(
|
|
118
119
|
opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>,
|
|
119
120
|
): Solid.Accessor<
|
|
120
|
-
false | ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']
|
|
121
|
+
false | Expand<ResolveRoute<TRouter, TFrom, TTo>['types']['allParams']>
|
|
121
122
|
> => {
|
|
122
123
|
const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts
|
|
123
124
|
|
package/src/fileRoute.ts
CHANGED
|
@@ -28,6 +28,7 @@ import type {
|
|
|
28
28
|
RouteIds,
|
|
29
29
|
RouteLoaderFn,
|
|
30
30
|
UpdatableRouteOptions,
|
|
31
|
+
UseNavigateResult,
|
|
31
32
|
} from '@tanstack/router-core'
|
|
32
33
|
import type { UseLoaderDepsRoute } from './useLoaderDeps'
|
|
33
34
|
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
@@ -41,8 +42,13 @@ export function createFileRoute<
|
|
|
41
42
|
TFullPath extends
|
|
42
43
|
RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],
|
|
43
44
|
>(
|
|
44
|
-
path
|
|
45
|
+
path?: TFilePath,
|
|
45
46
|
): 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
|
+
}
|
|
46
52
|
return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {
|
|
47
53
|
silent: true,
|
|
48
54
|
}).createRoute
|
|
@@ -63,7 +69,7 @@ export class FileRoute<
|
|
|
63
69
|
silent?: boolean
|
|
64
70
|
|
|
65
71
|
constructor(
|
|
66
|
-
public path
|
|
72
|
+
public path?: TFilePath,
|
|
67
73
|
_opts?: { silent: boolean },
|
|
68
74
|
) {
|
|
69
75
|
this.silent = _opts?.silent
|
|
@@ -159,6 +165,18 @@ export function FileRouteLoader<
|
|
|
159
165
|
return (loaderFn) => loaderFn as any
|
|
160
166
|
}
|
|
161
167
|
|
|
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
|
+
|
|
162
180
|
export class LazyRoute<TRoute extends AnyRoute> {
|
|
163
181
|
options: {
|
|
164
182
|
id: string
|
|
@@ -208,7 +226,7 @@ export class LazyRoute<TRoute extends AnyRoute> {
|
|
|
208
226
|
return useLoaderData({ ...opts, from: this.options.id } as any)
|
|
209
227
|
}
|
|
210
228
|
|
|
211
|
-
useNavigate = () => {
|
|
229
|
+
useNavigate = (): UseNavigateResult<TRoute['fullPath']> => {
|
|
212
230
|
const router = useRouter()
|
|
213
231
|
return useNavigate({ from: router.routesById[this.options.id].fullPath })
|
|
214
232
|
}
|
|
@@ -229,6 +247,10 @@ export function createLazyRoute<
|
|
|
229
247
|
export function createLazyFileRoute<
|
|
230
248
|
TFilePath extends keyof FileRoutesByPath,
|
|
231
249
|
TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],
|
|
232
|
-
>(id: TFilePath) {
|
|
250
|
+
>(id: TFilePath): (opts: LazyRouteOptions) => LazyRoute<TRoute> {
|
|
251
|
+
if (typeof id === 'object') {
|
|
252
|
+
return new LazyRoute<TRoute>(id) as any
|
|
253
|
+
}
|
|
254
|
+
|
|
233
255
|
return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })
|
|
234
256
|
}
|
package/src/index.tsx
CHANGED
|
@@ -47,7 +47,6 @@ export type {
|
|
|
47
47
|
DeferredPromiseState,
|
|
48
48
|
DeferredPromise,
|
|
49
49
|
ParsedLocation,
|
|
50
|
-
ParsePathParams,
|
|
51
50
|
RemoveTrailingSlashes,
|
|
52
51
|
RemoveLeadingSlashes,
|
|
53
52
|
ActiveOptions,
|
|
@@ -56,6 +55,8 @@ export type {
|
|
|
56
55
|
RootRouteId,
|
|
57
56
|
AnyPathParams,
|
|
58
57
|
ResolveParams,
|
|
58
|
+
ResolveOptionalParams,
|
|
59
|
+
ResolveRequiredParams,
|
|
59
60
|
SearchSchemaInput,
|
|
60
61
|
AnyContext,
|
|
61
62
|
RouteContext,
|
|
@@ -77,8 +78,6 @@ export type {
|
|
|
77
78
|
TrimPath,
|
|
78
79
|
TrimPathLeft,
|
|
79
80
|
TrimPathRight,
|
|
80
|
-
ParseSplatParams,
|
|
81
|
-
SplatParams,
|
|
82
81
|
StringifyParamsFn,
|
|
83
82
|
ParamsOptions,
|
|
84
83
|
InferAllParams,
|
|
@@ -207,6 +206,8 @@ export type {
|
|
|
207
206
|
InjectedHtmlEntry,
|
|
208
207
|
RouterErrorSerializer,
|
|
209
208
|
SerializerExtensions,
|
|
209
|
+
CreateFileRoute,
|
|
210
|
+
CreateLazyFileRoute,
|
|
210
211
|
} from '@tanstack/router-core'
|
|
211
212
|
|
|
212
213
|
export {
|
package/src/router.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { RouterCore } from '@tanstack/router-core'
|
|
2
|
+
import { createFileRoute, createLazyFileRoute } from './fileRoute'
|
|
2
3
|
import type { RouterHistory } from '@tanstack/history'
|
|
3
4
|
import type {
|
|
4
5
|
AnyRoute,
|
|
@@ -101,3 +102,11 @@ export class Router<
|
|
|
101
102
|
super(options)
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
|
|
106
|
+
if (typeof globalThis !== 'undefined') {
|
|
107
|
+
;(globalThis as any).createFileRoute = createFileRoute
|
|
108
|
+
;(globalThis as any).createLazyFileRoute = createLazyFileRoute
|
|
109
|
+
} else if (typeof window !== 'undefined') {
|
|
110
|
+
;(window as any).createFileRoute = createFileRoute
|
|
111
|
+
;(window as any).createFileRoute = createLazyFileRoute
|
|
112
|
+
}
|
package/src/useBlocker.tsx
CHANGED
|
@@ -180,7 +180,10 @@ export function useBlocker(
|
|
|
180
180
|
location: HistoryLocation,
|
|
181
181
|
): AnyShouldBlockFnLocation {
|
|
182
182
|
const parsedLocation = router.parseLocation(undefined, location)
|
|
183
|
-
const matchedRoutes = router.getMatchedRoutes(
|
|
183
|
+
const matchedRoutes = router.getMatchedRoutes(
|
|
184
|
+
parsedLocation.pathname,
|
|
185
|
+
undefined,
|
|
186
|
+
)
|
|
184
187
|
if (matchedRoutes.foundRoute === undefined) {
|
|
185
188
|
throw new Error(`No route found for location ${location.href}`)
|
|
186
189
|
}
|