@tanstack/solid-router 1.132.0-alpha.8 → 1.132.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/Asset.cjs +30 -1
- package/dist/cjs/Asset.cjs.map +1 -1
- package/dist/cjs/Matches.cjs +22 -18
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/RouterProvider.cjs +9 -9
- package/dist/cjs/RouterProvider.cjs.map +1 -1
- package/dist/cjs/ScriptOnce.cjs +12 -2
- package/dist/cjs/ScriptOnce.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +2 -2
- package/dist/cjs/index.cjs +8 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +4 -2
- package/dist/cjs/link.cjs +46 -31
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +9 -9
- package/dist/cjs/ssr/renderRouterToString.cjs +1 -0
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
- package/dist/cjs/useNavigate.cjs +1 -8
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useParams.cjs +3 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/esm/Asset.js +30 -1
- package/dist/esm/Asset.js.map +1 -1
- package/dist/esm/Matches.js +16 -12
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.js +9 -9
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/ScriptOnce.js +13 -3
- package/dist/esm/ScriptOnce.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +2 -2
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +4 -2
- package/dist/esm/index.js +3 -2
- package/dist/esm/link.js +46 -31
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/route.d.ts +9 -9
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +1 -0
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/useNavigate.js +1 -8
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.js +3 -2
- package/dist/esm/useParams.js.map +1 -1
- package/dist/source/Asset.jsx +33 -1
- package/dist/source/Asset.jsx.map +1 -1
- package/dist/source/Matches.jsx +11 -7
- package/dist/source/Matches.jsx.map +1 -1
- package/dist/source/RouterProvider.jsx +7 -7
- package/dist/source/RouterProvider.jsx.map +1 -1
- package/dist/source/ScriptOnce.jsx +4 -2
- package/dist/source/ScriptOnce.jsx.map +1 -1
- package/dist/source/fileRoute.d.ts +2 -2
- package/dist/source/fileRoute.js.map +1 -1
- package/dist/source/index.d.ts +4 -2
- package/dist/source/index.jsx +2 -1
- package/dist/source/index.jsx.map +1 -1
- package/dist/source/link.jsx +47 -36
- package/dist/source/link.jsx.map +1 -1
- package/dist/source/route.d.ts +9 -9
- package/dist/source/route.jsx.map +1 -1
- package/dist/source/ssr/renderRouterToString.jsx +1 -0
- package/dist/source/ssr/renderRouterToString.jsx.map +1 -1
- package/dist/source/useNavigate.jsx +1 -5
- package/dist/source/useNavigate.jsx.map +1 -1
- package/dist/source/useParams.jsx +3 -2
- package/dist/source/useParams.jsx.map +1 -1
- package/package.json +3 -3
- package/src/Asset.tsx +47 -1
- package/src/Matches.tsx +18 -16
- package/src/RouterProvider.tsx +9 -10
- package/src/ScriptOnce.tsx +5 -2
- package/src/fileRoute.ts +10 -3
- package/src/index.tsx +5 -2
- package/src/link.tsx +47 -41
- package/src/route.tsx +48 -22
- package/src/ssr/renderRouterToString.tsx +1 -0
- package/src/useNavigate.tsx +1 -9
- package/src/useParams.tsx +6 -4
- package/dist/cjs/useActiveLocation.cjs +0 -40
- package/dist/cjs/useActiveLocation.cjs.map +0 -1
- package/dist/cjs/useActiveLocation.d.cts +0 -8
- package/dist/esm/useActiveLocation.d.ts +0 -8
- package/dist/esm/useActiveLocation.js +0 -40
- package/dist/esm/useActiveLocation.js.map +0 -1
- package/dist/source/useActiveLocation.d.ts +0 -8
- package/dist/source/useActiveLocation.js +0 -33
- package/dist/source/useActiveLocation.js.map +0 -1
- package/src/useActiveLocation.ts +0 -61
package/src/link.tsx
CHANGED
|
@@ -15,7 +15,6 @@ import { useRouter } from './useRouter'
|
|
|
15
15
|
|
|
16
16
|
import { useIntersectionObserver } from './utils'
|
|
17
17
|
|
|
18
|
-
import { useActiveLocation } from './useActiveLocation'
|
|
19
18
|
import type {
|
|
20
19
|
AnyRouter,
|
|
21
20
|
Constrain,
|
|
@@ -115,43 +114,60 @@ export function useLinkProps<
|
|
|
115
114
|
'unsafeRelative',
|
|
116
115
|
])
|
|
117
116
|
|
|
118
|
-
// If this link simply reloads the current route,
|
|
119
|
-
// make sure it has a new key so it will trigger a data refresh
|
|
120
|
-
|
|
121
|
-
// If this `to` is a valid external URL, return
|
|
122
|
-
// null for LinkUtils
|
|
123
|
-
|
|
124
|
-
const type: Solid.Accessor<'internal' | 'external'> = () => {
|
|
125
|
-
try {
|
|
126
|
-
new URL(`${local.to}`)
|
|
127
|
-
return 'external'
|
|
128
|
-
} catch {}
|
|
129
|
-
return 'internal'
|
|
130
|
-
}
|
|
131
|
-
|
|
132
117
|
const currentSearch = useRouterState({
|
|
133
118
|
select: (s) => s.location.searchStr,
|
|
134
119
|
})
|
|
135
120
|
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
const from = getFromPath(options.from)
|
|
121
|
+
const from = options.from
|
|
139
122
|
|
|
140
123
|
const _options = () => {
|
|
141
124
|
return {
|
|
142
125
|
...options,
|
|
143
|
-
from
|
|
126
|
+
from,
|
|
144
127
|
}
|
|
145
128
|
}
|
|
146
129
|
|
|
147
130
|
const next = Solid.createMemo(() => {
|
|
148
131
|
currentSearch()
|
|
149
|
-
activeLocation()
|
|
150
132
|
return router.buildLocation(_options() as any)
|
|
151
133
|
})
|
|
152
134
|
|
|
135
|
+
const hrefOption = Solid.createMemo(() => {
|
|
136
|
+
if (_options().disabled) {
|
|
137
|
+
return undefined
|
|
138
|
+
}
|
|
139
|
+
let href
|
|
140
|
+
const maskedLocation = next().maskedLocation
|
|
141
|
+
if (maskedLocation) {
|
|
142
|
+
href = maskedLocation.url
|
|
143
|
+
} else {
|
|
144
|
+
href = next().url
|
|
145
|
+
}
|
|
146
|
+
let external = false
|
|
147
|
+
if (router.origin) {
|
|
148
|
+
if (href.startsWith(router.origin)) {
|
|
149
|
+
href = href.replace(router.origin, '')
|
|
150
|
+
} else {
|
|
151
|
+
external = true
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return { href, external }
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
const externalLink = Solid.createMemo(() => {
|
|
158
|
+
const _href = hrefOption()
|
|
159
|
+
if (_href?.external) {
|
|
160
|
+
return _href.href
|
|
161
|
+
}
|
|
162
|
+
try {
|
|
163
|
+
new URL(_options().to as any)
|
|
164
|
+
return _options().to
|
|
165
|
+
} catch {}
|
|
166
|
+
return undefined
|
|
167
|
+
})
|
|
168
|
+
|
|
153
169
|
const preload = Solid.createMemo(() => {
|
|
154
|
-
if (_options().reloadDocument) {
|
|
170
|
+
if (_options().reloadDocument || externalLink()) {
|
|
155
171
|
return false
|
|
156
172
|
}
|
|
157
173
|
return local.preload ?? router.options.defaultPreload
|
|
@@ -161,6 +177,7 @@ export function useLinkProps<
|
|
|
161
177
|
|
|
162
178
|
const isActive = useRouterState({
|
|
163
179
|
select: (s) => {
|
|
180
|
+
if (externalLink()) return false
|
|
164
181
|
if (local.activeOptions?.exact) {
|
|
165
182
|
const testExact = exactPathTest(
|
|
166
183
|
s.location.pathname,
|
|
@@ -238,17 +255,12 @@ export function useLinkProps<
|
|
|
238
255
|
}
|
|
239
256
|
})
|
|
240
257
|
|
|
241
|
-
if (
|
|
258
|
+
if (externalLink()) {
|
|
242
259
|
return Solid.mergeProps(
|
|
243
260
|
propsSafeToSpread,
|
|
244
261
|
{
|
|
245
262
|
ref,
|
|
246
|
-
|
|
247
|
-
return type()
|
|
248
|
-
},
|
|
249
|
-
get href() {
|
|
250
|
-
return local.to
|
|
251
|
-
},
|
|
263
|
+
href: externalLink,
|
|
252
264
|
},
|
|
253
265
|
Solid.splitProps(local, [
|
|
254
266
|
'target',
|
|
@@ -268,11 +280,16 @@ export function useLinkProps<
|
|
|
268
280
|
|
|
269
281
|
// The click handler
|
|
270
282
|
const handleClick = (e: MouseEvent) => {
|
|
283
|
+
// Check actual element's target attribute as fallback
|
|
284
|
+
const elementTarget = (e.currentTarget as HTMLAnchorElement).target
|
|
285
|
+
const effectiveTarget =
|
|
286
|
+
local.target !== undefined ? local.target : elementTarget
|
|
287
|
+
|
|
271
288
|
if (
|
|
272
289
|
!local.disabled &&
|
|
273
290
|
!isCtrlEvent(e) &&
|
|
274
291
|
!e.defaultPrevented &&
|
|
275
|
-
(!
|
|
292
|
+
(!effectiveTarget || effectiveTarget === '_self') &&
|
|
276
293
|
e.button === 0
|
|
277
294
|
) {
|
|
278
295
|
e.preventDefault()
|
|
@@ -384,24 +401,13 @@ export function useLinkProps<
|
|
|
384
401
|
...resolvedInactiveProps().style,
|
|
385
402
|
})
|
|
386
403
|
|
|
387
|
-
const href = Solid.createMemo(() => {
|
|
388
|
-
const nextLocation = next()
|
|
389
|
-
const maskedLocation = nextLocation?.maskedLocation
|
|
390
|
-
|
|
391
|
-
return _options().disabled
|
|
392
|
-
? undefined
|
|
393
|
-
: maskedLocation
|
|
394
|
-
? router.history.createHref(maskedLocation.href)
|
|
395
|
-
: router.history.createHref(nextLocation?.href)
|
|
396
|
-
})
|
|
397
|
-
|
|
398
404
|
return Solid.mergeProps(
|
|
399
405
|
propsSafeToSpread,
|
|
400
406
|
resolvedActiveProps,
|
|
401
407
|
resolvedInactiveProps,
|
|
402
408
|
() => {
|
|
403
409
|
return {
|
|
404
|
-
href:
|
|
410
|
+
href: hrefOption()?.href,
|
|
405
411
|
ref: mergeRefs(setRef, _options().ref),
|
|
406
412
|
onClick: composeEventHandlers([local.onClick, handleClick]),
|
|
407
413
|
onFocus: composeEventHandlers([local.onFocus, handleFocus]),
|
package/src/route.tsx
CHANGED
|
@@ -153,7 +153,7 @@ export class RouteApi<
|
|
|
153
153
|
}
|
|
154
154
|
|
|
155
155
|
export class Route<
|
|
156
|
-
in out TRegister
|
|
156
|
+
in out TRegister = unknown,
|
|
157
157
|
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
158
158
|
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
159
159
|
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
@@ -176,6 +176,8 @@ export class Route<
|
|
|
176
176
|
in out TChildren = unknown,
|
|
177
177
|
in out TFileRouteTypes = unknown,
|
|
178
178
|
in out TSSR = unknown,
|
|
179
|
+
in out TMiddlewares = unknown,
|
|
180
|
+
in out THandlers = undefined,
|
|
179
181
|
>
|
|
180
182
|
extends BaseRoute<
|
|
181
183
|
TRegister,
|
|
@@ -193,7 +195,9 @@ export class Route<
|
|
|
193
195
|
TLoaderFn,
|
|
194
196
|
TChildren,
|
|
195
197
|
TFileRouteTypes,
|
|
196
|
-
TSSR
|
|
198
|
+
TSSR,
|
|
199
|
+
TMiddlewares,
|
|
200
|
+
THandlers
|
|
197
201
|
>
|
|
198
202
|
implements
|
|
199
203
|
RouteCore<
|
|
@@ -212,7 +216,9 @@ export class Route<
|
|
|
212
216
|
TLoaderFn,
|
|
213
217
|
TChildren,
|
|
214
218
|
TFileRouteTypes,
|
|
215
|
-
TSSR
|
|
219
|
+
TSSR,
|
|
220
|
+
TMiddlewares,
|
|
221
|
+
THandlers
|
|
216
222
|
>
|
|
217
223
|
{
|
|
218
224
|
/**
|
|
@@ -233,7 +239,9 @@ export class Route<
|
|
|
233
239
|
TRouterContext,
|
|
234
240
|
TRouteContextFn,
|
|
235
241
|
TBeforeLoadFn,
|
|
236
|
-
TSSR
|
|
242
|
+
TSSR,
|
|
243
|
+
TMiddlewares,
|
|
244
|
+
THandlers
|
|
237
245
|
>,
|
|
238
246
|
) {
|
|
239
247
|
super(options)
|
|
@@ -286,7 +294,7 @@ export class Route<
|
|
|
286
294
|
}
|
|
287
295
|
|
|
288
296
|
export function createRoute<
|
|
289
|
-
TRegister
|
|
297
|
+
TRegister = unknown,
|
|
290
298
|
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
291
299
|
TPath extends RouteConstraints['TPath'] = '/',
|
|
292
300
|
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
@@ -307,6 +315,7 @@ export function createRoute<
|
|
|
307
315
|
TLoaderFn = undefined,
|
|
308
316
|
TChildren = unknown,
|
|
309
317
|
TSSR = unknown,
|
|
318
|
+
THandlers = undefined,
|
|
310
319
|
>(
|
|
311
320
|
options: RouteOptions<
|
|
312
321
|
TRegister,
|
|
@@ -322,7 +331,8 @@ export function createRoute<
|
|
|
322
331
|
AnyContext,
|
|
323
332
|
TRouteContextFn,
|
|
324
333
|
TBeforeLoadFn,
|
|
325
|
-
TSSR
|
|
334
|
+
TSSR,
|
|
335
|
+
THandlers
|
|
326
336
|
>,
|
|
327
337
|
): Route<
|
|
328
338
|
TRegister,
|
|
@@ -340,7 +350,8 @@ export function createRoute<
|
|
|
340
350
|
TLoaderFn,
|
|
341
351
|
TChildren,
|
|
342
352
|
unknown,
|
|
343
|
-
TSSR
|
|
353
|
+
TSSR,
|
|
354
|
+
THandlers
|
|
344
355
|
> {
|
|
345
356
|
return new Route<
|
|
346
357
|
TRegister,
|
|
@@ -358,7 +369,8 @@ export function createRoute<
|
|
|
358
369
|
TLoaderFn,
|
|
359
370
|
TChildren,
|
|
360
371
|
unknown,
|
|
361
|
-
TSSR
|
|
372
|
+
TSSR,
|
|
373
|
+
THandlers
|
|
362
374
|
>(options)
|
|
363
375
|
}
|
|
364
376
|
|
|
@@ -377,13 +389,14 @@ export type AnyRootRoute = RootRoute<
|
|
|
377
389
|
|
|
378
390
|
export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
379
391
|
return <
|
|
380
|
-
TRegister
|
|
392
|
+
TRegister = Register,
|
|
381
393
|
TRouteContextFn = AnyContext,
|
|
382
394
|
TBeforeLoadFn = AnyContext,
|
|
383
395
|
TSearchValidator = undefined,
|
|
384
396
|
TLoaderDeps extends Record<string, any> = {},
|
|
385
397
|
TLoaderFn = undefined,
|
|
386
398
|
TSSR = unknown,
|
|
399
|
+
THandlers = undefined,
|
|
387
400
|
>(
|
|
388
401
|
options?: RootRouteOptions<
|
|
389
402
|
TRegister,
|
|
@@ -393,7 +406,8 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
393
406
|
TBeforeLoadFn,
|
|
394
407
|
TLoaderDeps,
|
|
395
408
|
TLoaderFn,
|
|
396
|
-
TSSR
|
|
409
|
+
TSSR,
|
|
410
|
+
THandlers
|
|
397
411
|
>,
|
|
398
412
|
) => {
|
|
399
413
|
return createRootRoute<
|
|
@@ -404,7 +418,8 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
404
418
|
TBeforeLoadFn,
|
|
405
419
|
TLoaderDeps,
|
|
406
420
|
TLoaderFn,
|
|
407
|
-
TSSR
|
|
421
|
+
TSSR,
|
|
422
|
+
THandlers
|
|
408
423
|
>(options as any)
|
|
409
424
|
}
|
|
410
425
|
}
|
|
@@ -415,7 +430,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
|
415
430
|
export const rootRouteWithContext = createRootRouteWithContext
|
|
416
431
|
|
|
417
432
|
export class RootRoute<
|
|
418
|
-
in out TRegister
|
|
433
|
+
in out TRegister = Register,
|
|
419
434
|
in out TSearchValidator = undefined,
|
|
420
435
|
in out TRouterContext = {},
|
|
421
436
|
in out TRouteContextFn = AnyContext,
|
|
@@ -425,6 +440,7 @@ export class RootRoute<
|
|
|
425
440
|
in out TChildren = unknown,
|
|
426
441
|
in out TFileRouteTypes = unknown,
|
|
427
442
|
in out TSSR = unknown,
|
|
443
|
+
in out THandlers = undefined,
|
|
428
444
|
>
|
|
429
445
|
extends BaseRootRoute<
|
|
430
446
|
TRegister,
|
|
@@ -436,7 +452,8 @@ export class RootRoute<
|
|
|
436
452
|
TLoaderFn,
|
|
437
453
|
TChildren,
|
|
438
454
|
TFileRouteTypes,
|
|
439
|
-
TSSR
|
|
455
|
+
TSSR,
|
|
456
|
+
THandlers
|
|
440
457
|
>
|
|
441
458
|
implements
|
|
442
459
|
RootRouteCore<
|
|
@@ -449,7 +466,8 @@ export class RootRoute<
|
|
|
449
466
|
TLoaderFn,
|
|
450
467
|
TChildren,
|
|
451
468
|
TFileRouteTypes,
|
|
452
|
-
TSSR
|
|
469
|
+
TSSR,
|
|
470
|
+
THandlers
|
|
453
471
|
>
|
|
454
472
|
{
|
|
455
473
|
/**
|
|
@@ -464,7 +482,8 @@ export class RootRoute<
|
|
|
464
482
|
TBeforeLoadFn,
|
|
465
483
|
TLoaderDeps,
|
|
466
484
|
TLoaderFn,
|
|
467
|
-
TSSR
|
|
485
|
+
TSSR,
|
|
486
|
+
THandlers
|
|
468
487
|
>,
|
|
469
488
|
) {
|
|
470
489
|
super(options)
|
|
@@ -546,7 +565,7 @@ export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>
|
|
|
546
565
|
export type NotFoundRouteComponent = RouteTypes<NotFoundRouteProps>['component']
|
|
547
566
|
|
|
548
567
|
export class NotFoundRoute<
|
|
549
|
-
TRegister
|
|
568
|
+
TRegister,
|
|
550
569
|
TParentRoute extends AnyRootRoute,
|
|
551
570
|
TRouterContext = AnyContext,
|
|
552
571
|
TRouteContextFn = AnyContext,
|
|
@@ -556,6 +575,7 @@ export class NotFoundRoute<
|
|
|
556
575
|
TLoaderFn = undefined,
|
|
557
576
|
TChildren = unknown,
|
|
558
577
|
TSSR = unknown,
|
|
578
|
+
THandlers = undefined,
|
|
559
579
|
> extends Route<
|
|
560
580
|
TRegister,
|
|
561
581
|
TParentRoute,
|
|
@@ -571,7 +591,8 @@ export class NotFoundRoute<
|
|
|
571
591
|
TLoaderDeps,
|
|
572
592
|
TLoaderFn,
|
|
573
593
|
TChildren,
|
|
574
|
-
TSSR
|
|
594
|
+
TSSR,
|
|
595
|
+
THandlers
|
|
575
596
|
> {
|
|
576
597
|
constructor(
|
|
577
598
|
options: Omit<
|
|
@@ -589,7 +610,8 @@ export class NotFoundRoute<
|
|
|
589
610
|
TRouterContext,
|
|
590
611
|
TRouteContextFn,
|
|
591
612
|
TBeforeLoadFn,
|
|
592
|
-
TSSR
|
|
613
|
+
TSSR,
|
|
614
|
+
THandlers
|
|
593
615
|
>,
|
|
594
616
|
| 'caseSensitive'
|
|
595
617
|
| 'parseParams'
|
|
@@ -607,7 +629,7 @@ export class NotFoundRoute<
|
|
|
607
629
|
}
|
|
608
630
|
|
|
609
631
|
export function createRootRoute<
|
|
610
|
-
TRegister
|
|
632
|
+
TRegister = Register,
|
|
611
633
|
TSearchValidator = undefined,
|
|
612
634
|
TRouterContext = {},
|
|
613
635
|
TRouteContextFn = AnyContext,
|
|
@@ -615,6 +637,7 @@ export function createRootRoute<
|
|
|
615
637
|
TLoaderDeps extends Record<string, any> = {},
|
|
616
638
|
TLoaderFn = undefined,
|
|
617
639
|
TSSR = unknown,
|
|
640
|
+
THandlers = undefined,
|
|
618
641
|
>(
|
|
619
642
|
options?: RootRouteOptions<
|
|
620
643
|
TRegister,
|
|
@@ -624,7 +647,8 @@ export function createRootRoute<
|
|
|
624
647
|
TBeforeLoadFn,
|
|
625
648
|
TLoaderDeps,
|
|
626
649
|
TLoaderFn,
|
|
627
|
-
TSSR
|
|
650
|
+
TSSR,
|
|
651
|
+
THandlers
|
|
628
652
|
>,
|
|
629
653
|
): RootRoute<
|
|
630
654
|
TRegister,
|
|
@@ -636,7 +660,8 @@ export function createRootRoute<
|
|
|
636
660
|
TLoaderFn,
|
|
637
661
|
unknown,
|
|
638
662
|
unknown,
|
|
639
|
-
TSSR
|
|
663
|
+
TSSR,
|
|
664
|
+
THandlers
|
|
640
665
|
> {
|
|
641
666
|
return new RootRoute<
|
|
642
667
|
TRegister,
|
|
@@ -648,6 +673,7 @@ export function createRootRoute<
|
|
|
648
673
|
TLoaderFn,
|
|
649
674
|
unknown,
|
|
650
675
|
unknown,
|
|
651
|
-
TSSR
|
|
676
|
+
TSSR,
|
|
677
|
+
THandlers
|
|
652
678
|
>(options)
|
|
653
679
|
}
|
|
@@ -13,6 +13,7 @@ export const renderRouterToString = async ({
|
|
|
13
13
|
}) => {
|
|
14
14
|
try {
|
|
15
15
|
let html = Solid.renderToString(children)
|
|
16
|
+
router.serverSsr!.setRenderFinished()
|
|
16
17
|
const injectedHtml = await Promise.all(router.serverSsr!.injectedHtml).then(
|
|
17
18
|
(htmls) => htmls.join(''),
|
|
18
19
|
)
|
package/src/useNavigate.tsx
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as Solid from 'solid-js'
|
|
2
2
|
import { useRouter } from './useRouter'
|
|
3
|
-
import { useActiveLocation } from './useActiveLocation'
|
|
4
3
|
import type {
|
|
5
4
|
AnyRouter,
|
|
6
5
|
FromPathOption,
|
|
@@ -17,17 +16,10 @@ export function useNavigate<
|
|
|
17
16
|
}): UseNavigateResult<TDefaultFrom> {
|
|
18
17
|
const router = useRouter()
|
|
19
18
|
|
|
20
|
-
const { getFromPath, setActiveLocation } = useActiveLocation(
|
|
21
|
-
router.latestLocation,
|
|
22
|
-
)
|
|
23
|
-
|
|
24
19
|
return ((options: NavigateOptions) => {
|
|
25
|
-
setActiveLocation(router.latestLocation)
|
|
26
|
-
const from = getFromPath(options.from ?? _defaultOpts?.from)
|
|
27
|
-
|
|
28
20
|
return router.navigate({
|
|
29
21
|
...options,
|
|
30
|
-
from: from
|
|
22
|
+
from: options.from ?? _defaultOpts?.from,
|
|
31
23
|
})
|
|
32
24
|
}) as UseNavigateResult<TDefaultFrom>
|
|
33
25
|
}
|
package/src/useParams.tsx
CHANGED
|
@@ -62,10 +62,12 @@ export function useParams<
|
|
|
62
62
|
> {
|
|
63
63
|
return useMatch({
|
|
64
64
|
from: opts.from!,
|
|
65
|
-
strict: opts.strict,
|
|
66
65
|
shouldThrow: opts.shouldThrow,
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
strict: opts.strict,
|
|
67
|
+
select: (match) => {
|
|
68
|
+
const params = opts.strict === false ? match.params : match._strictParams
|
|
69
|
+
|
|
70
|
+
return opts.select ? opts.select(params) : params
|
|
69
71
|
},
|
|
70
|
-
}
|
|
72
|
+
}) as Accessor<any>
|
|
71
73
|
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const routerCore = require("@tanstack/router-core");
|
|
4
|
-
const Solid = require("solid-js");
|
|
5
|
-
const useMatch = require("./useMatch.cjs");
|
|
6
|
-
const useRouter = require("./useRouter.cjs");
|
|
7
|
-
const useRouterState = require("./useRouterState.cjs");
|
|
8
|
-
function useActiveLocation(location) {
|
|
9
|
-
const router = useRouter.useRouter();
|
|
10
|
-
const [activeLocation, setActiveLocation] = Solid.createSignal(
|
|
11
|
-
location ?? useRouterState.useRouterState({ select: (s) => s.location })()
|
|
12
|
-
);
|
|
13
|
-
const [customActiveLocation, setCustomActiveLocation] = Solid.createSignal(location);
|
|
14
|
-
Solid.createEffect(() => {
|
|
15
|
-
setActiveLocation(
|
|
16
|
-
customActiveLocation() ?? useRouterState.useRouterState({ select: (s) => s.location })()
|
|
17
|
-
);
|
|
18
|
-
});
|
|
19
|
-
const matchIndex = useMatch.useMatch({
|
|
20
|
-
strict: false,
|
|
21
|
-
select: (match) => match.index
|
|
22
|
-
});
|
|
23
|
-
const getFromPath = (from) => Solid.createMemo(() => {
|
|
24
|
-
const activeLocationMatches = router.matchRoutes(
|
|
25
|
-
customActiveLocation() ?? activeLocation(),
|
|
26
|
-
{
|
|
27
|
-
_buildLocation: false
|
|
28
|
-
}
|
|
29
|
-
);
|
|
30
|
-
const activeLocationMatch = routerCore.last(activeLocationMatches);
|
|
31
|
-
return from ?? activeLocationMatch?.fullPath ?? router.state.matches[matchIndex()].fullPath;
|
|
32
|
-
});
|
|
33
|
-
return {
|
|
34
|
-
activeLocation,
|
|
35
|
-
getFromPath,
|
|
36
|
-
setActiveLocation: setCustomActiveLocation
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
exports.useActiveLocation = useActiveLocation;
|
|
40
|
-
//# sourceMappingURL=useActiveLocation.cjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveLocation.cjs","sources":["../../src/useActiveLocation.ts"],"sourcesContent":["import { last } from '@tanstack/router-core'\nimport { createEffect, createMemo, createSignal } from 'solid-js'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport type { Accessor } from 'solid-js'\nimport type { ParsedLocation } from '@tanstack/router-core'\n\nexport type UseLocationResult = {\n activeLocation: Accessor<ParsedLocation>\n getFromPath: (from?: string) => Accessor<string>\n setActiveLocation: (location?: ParsedLocation) => void\n}\n\nexport function useActiveLocation(\n location?: ParsedLocation,\n): UseLocationResult {\n const router = useRouter()\n // we are not using a variable here for router state location since we need to only calculate that if the location is not passed in. It can result in unnecessary history actions if we do that.\n const [activeLocation, setActiveLocation] = createSignal<ParsedLocation>(\n location ?? useRouterState({ select: (s) => s.location })(),\n )\n const [customActiveLocation, setCustomActiveLocation] = createSignal<\n ParsedLocation | undefined\n >(location)\n\n createEffect(() => {\n setActiveLocation(\n customActiveLocation() ?? useRouterState({ select: (s) => s.location })(),\n )\n })\n\n const matchIndex = useMatch({\n strict: false,\n select: (match) => match.index,\n })\n\n const getFromPath = (from?: string) =>\n createMemo(() => {\n const activeLocationMatches = router.matchRoutes(\n customActiveLocation() ?? activeLocation(),\n {\n _buildLocation: false,\n },\n )\n\n const activeLocationMatch = last(activeLocationMatches)\n\n return (\n from ??\n activeLocationMatch?.fullPath ??\n router.state.matches[matchIndex()]!.fullPath\n )\n })\n\n return {\n activeLocation,\n getFromPath,\n setActiveLocation: setCustomActiveLocation,\n }\n}\n"],"names":["useRouter","createSignal","useRouterState","createEffect","useMatch","createMemo","last"],"mappings":";;;;;;;AAcO,SAAS,kBACd,UACmB;AACnB,QAAM,SAASA,UAAAA,UAAA;AAEf,QAAM,CAAC,gBAAgB,iBAAiB,IAAIC,MAAAA;AAAAA,IAC1C,YAAYC,eAAAA,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAA;AAAA,EAAE;AAE5D,QAAM,CAAC,sBAAsB,uBAAuB,IAAID,MAAAA,aAEtD,QAAQ;AAEVE,QAAAA,aAAa,MAAM;AACjB;AAAA,MACE,qBAAA,KAA0BD,eAAAA,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAA;AAAA,IAAE;AAAA,EAE5E,CAAC;AAED,QAAM,aAAaE,SAAAA,SAAS;AAAA,IAC1B,QAAQ;AAAA,IACR,QAAQ,CAAC,UAAU,MAAM;AAAA,EAAA,CAC1B;AAED,QAAM,cAAc,CAAC,SACnBC,MAAAA,WAAW,MAAM;AACf,UAAM,wBAAwB,OAAO;AAAA,MACnC,qBAAA,KAA0B,eAAA;AAAA,MAC1B;AAAA,QACE,gBAAgB;AAAA,MAAA;AAAA,IAClB;AAGF,UAAM,sBAAsBC,WAAAA,KAAK,qBAAqB;AAEtD,WACE,QACA,qBAAqB,YACrB,OAAO,MAAM,QAAQ,WAAA,CAAY,EAAG;AAAA,EAExC,CAAC;AAEH,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,EAAA;AAEvB;;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Accessor } from 'solid-js';
|
|
2
|
-
import { ParsedLocation } from '@tanstack/router-core';
|
|
3
|
-
export type UseLocationResult = {
|
|
4
|
-
activeLocation: Accessor<ParsedLocation>;
|
|
5
|
-
getFromPath: (from?: string) => Accessor<string>;
|
|
6
|
-
setActiveLocation: (location?: ParsedLocation) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare function useActiveLocation(location?: ParsedLocation): UseLocationResult;
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { Accessor } from 'solid-js';
|
|
2
|
-
import { ParsedLocation } from '@tanstack/router-core';
|
|
3
|
-
export type UseLocationResult = {
|
|
4
|
-
activeLocation: Accessor<ParsedLocation>;
|
|
5
|
-
getFromPath: (from?: string) => Accessor<string>;
|
|
6
|
-
setActiveLocation: (location?: ParsedLocation) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare function useActiveLocation(location?: ParsedLocation): UseLocationResult;
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { last } from "@tanstack/router-core";
|
|
2
|
-
import { createSignal, createEffect, createMemo } from "solid-js";
|
|
3
|
-
import { useMatch } from "./useMatch.js";
|
|
4
|
-
import { useRouter } from "./useRouter.js";
|
|
5
|
-
import { useRouterState } from "./useRouterState.js";
|
|
6
|
-
function useActiveLocation(location) {
|
|
7
|
-
const router = useRouter();
|
|
8
|
-
const [activeLocation, setActiveLocation] = createSignal(
|
|
9
|
-
location ?? useRouterState({ select: (s) => s.location })()
|
|
10
|
-
);
|
|
11
|
-
const [customActiveLocation, setCustomActiveLocation] = createSignal(location);
|
|
12
|
-
createEffect(() => {
|
|
13
|
-
setActiveLocation(
|
|
14
|
-
customActiveLocation() ?? useRouterState({ select: (s) => s.location })()
|
|
15
|
-
);
|
|
16
|
-
});
|
|
17
|
-
const matchIndex = useMatch({
|
|
18
|
-
strict: false,
|
|
19
|
-
select: (match) => match.index
|
|
20
|
-
});
|
|
21
|
-
const getFromPath = (from) => createMemo(() => {
|
|
22
|
-
const activeLocationMatches = router.matchRoutes(
|
|
23
|
-
customActiveLocation() ?? activeLocation(),
|
|
24
|
-
{
|
|
25
|
-
_buildLocation: false
|
|
26
|
-
}
|
|
27
|
-
);
|
|
28
|
-
const activeLocationMatch = last(activeLocationMatches);
|
|
29
|
-
return from ?? activeLocationMatch?.fullPath ?? router.state.matches[matchIndex()].fullPath;
|
|
30
|
-
});
|
|
31
|
-
return {
|
|
32
|
-
activeLocation,
|
|
33
|
-
getFromPath,
|
|
34
|
-
setActiveLocation: setCustomActiveLocation
|
|
35
|
-
};
|
|
36
|
-
}
|
|
37
|
-
export {
|
|
38
|
-
useActiveLocation
|
|
39
|
-
};
|
|
40
|
-
//# sourceMappingURL=useActiveLocation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveLocation.js","sources":["../../src/useActiveLocation.ts"],"sourcesContent":["import { last } from '@tanstack/router-core'\nimport { createEffect, createMemo, createSignal } from 'solid-js'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport type { Accessor } from 'solid-js'\nimport type { ParsedLocation } from '@tanstack/router-core'\n\nexport type UseLocationResult = {\n activeLocation: Accessor<ParsedLocation>\n getFromPath: (from?: string) => Accessor<string>\n setActiveLocation: (location?: ParsedLocation) => void\n}\n\nexport function useActiveLocation(\n location?: ParsedLocation,\n): UseLocationResult {\n const router = useRouter()\n // we are not using a variable here for router state location since we need to only calculate that if the location is not passed in. It can result in unnecessary history actions if we do that.\n const [activeLocation, setActiveLocation] = createSignal<ParsedLocation>(\n location ?? useRouterState({ select: (s) => s.location })(),\n )\n const [customActiveLocation, setCustomActiveLocation] = createSignal<\n ParsedLocation | undefined\n >(location)\n\n createEffect(() => {\n setActiveLocation(\n customActiveLocation() ?? useRouterState({ select: (s) => s.location })(),\n )\n })\n\n const matchIndex = useMatch({\n strict: false,\n select: (match) => match.index,\n })\n\n const getFromPath = (from?: string) =>\n createMemo(() => {\n const activeLocationMatches = router.matchRoutes(\n customActiveLocation() ?? activeLocation(),\n {\n _buildLocation: false,\n },\n )\n\n const activeLocationMatch = last(activeLocationMatches)\n\n return (\n from ??\n activeLocationMatch?.fullPath ??\n router.state.matches[matchIndex()]!.fullPath\n )\n })\n\n return {\n activeLocation,\n getFromPath,\n setActiveLocation: setCustomActiveLocation,\n }\n}\n"],"names":[],"mappings":";;;;;AAcO,SAAS,kBACd,UACmB;AACnB,QAAM,SAAS,UAAA;AAEf,QAAM,CAAC,gBAAgB,iBAAiB,IAAI;AAAA,IAC1C,YAAY,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAA;AAAA,EAAE;AAE5D,QAAM,CAAC,sBAAsB,uBAAuB,IAAI,aAEtD,QAAQ;AAEV,eAAa,MAAM;AACjB;AAAA,MACE,qBAAA,KAA0B,eAAe,EAAE,QAAQ,CAAC,MAAM,EAAE,UAAU,EAAA;AAAA,IAAE;AAAA,EAE5E,CAAC;AAED,QAAM,aAAa,SAAS;AAAA,IAC1B,QAAQ;AAAA,IACR,QAAQ,CAAC,UAAU,MAAM;AAAA,EAAA,CAC1B;AAED,QAAM,cAAc,CAAC,SACnB,WAAW,MAAM;AACf,UAAM,wBAAwB,OAAO;AAAA,MACnC,qBAAA,KAA0B,eAAA;AAAA,MAC1B;AAAA,QACE,gBAAgB;AAAA,MAAA;AAAA,IAClB;AAGF,UAAM,sBAAsB,KAAK,qBAAqB;AAEtD,WACE,QACA,qBAAqB,YACrB,OAAO,MAAM,QAAQ,WAAA,CAAY,EAAG;AAAA,EAExC,CAAC;AAEH,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,EAAA;AAEvB;"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { Accessor } from 'solid-js';
|
|
2
|
-
import type { ParsedLocation } from '@tanstack/router-core';
|
|
3
|
-
export type UseLocationResult = {
|
|
4
|
-
activeLocation: Accessor<ParsedLocation>;
|
|
5
|
-
getFromPath: (from?: string) => Accessor<string>;
|
|
6
|
-
setActiveLocation: (location?: ParsedLocation) => void;
|
|
7
|
-
};
|
|
8
|
-
export declare function useActiveLocation(location?: ParsedLocation): UseLocationResult;
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { last } from '@tanstack/router-core';
|
|
2
|
-
import { createEffect, createMemo, createSignal } from 'solid-js';
|
|
3
|
-
import { useMatch } from './useMatch';
|
|
4
|
-
import { useRouter } from './useRouter';
|
|
5
|
-
import { useRouterState } from './useRouterState';
|
|
6
|
-
export function useActiveLocation(location) {
|
|
7
|
-
const router = useRouter();
|
|
8
|
-
// we are not using a variable here for router state location since we need to only calculate that if the location is not passed in. It can result in unnecessary history actions if we do that.
|
|
9
|
-
const [activeLocation, setActiveLocation] = createSignal(location ?? useRouterState({ select: (s) => s.location })());
|
|
10
|
-
const [customActiveLocation, setCustomActiveLocation] = createSignal(location);
|
|
11
|
-
createEffect(() => {
|
|
12
|
-
setActiveLocation(customActiveLocation() ?? useRouterState({ select: (s) => s.location })());
|
|
13
|
-
});
|
|
14
|
-
const matchIndex = useMatch({
|
|
15
|
-
strict: false,
|
|
16
|
-
select: (match) => match.index,
|
|
17
|
-
});
|
|
18
|
-
const getFromPath = (from) => createMemo(() => {
|
|
19
|
-
const activeLocationMatches = router.matchRoutes(customActiveLocation() ?? activeLocation(), {
|
|
20
|
-
_buildLocation: false,
|
|
21
|
-
});
|
|
22
|
-
const activeLocationMatch = last(activeLocationMatches);
|
|
23
|
-
return (from ??
|
|
24
|
-
activeLocationMatch?.fullPath ??
|
|
25
|
-
router.state.matches[matchIndex()].fullPath);
|
|
26
|
-
});
|
|
27
|
-
return {
|
|
28
|
-
activeLocation,
|
|
29
|
-
getFromPath,
|
|
30
|
-
setActiveLocation: setCustomActiveLocation,
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
//# sourceMappingURL=useActiveLocation.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActiveLocation.js","sourceRoot":"","sources":["../../src/useActiveLocation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,uBAAuB,CAAA;AAC5C,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AACjE,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AACrC,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAUjD,MAAM,UAAU,iBAAiB,CAC/B,QAAyB;IAEzB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAA;IAC1B,gMAAgM;IAChM,MAAM,CAAC,cAAc,EAAE,iBAAiB,CAAC,GAAG,YAAY,CACtD,QAAQ,IAAI,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,CAC5D,CAAA;IACD,MAAM,CAAC,oBAAoB,EAAE,uBAAuB,CAAC,GAAG,YAAY,CAElE,QAAQ,CAAC,CAAA;IAEX,YAAY,CAAC,GAAG,EAAE;QAChB,iBAAiB,CACf,oBAAoB,EAAE,IAAI,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,EAAE,CAC1E,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,MAAM,UAAU,GAAG,QAAQ,CAAC;QAC1B,MAAM,EAAE,KAAK;QACb,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK;KAC/B,CAAC,CAAA;IAEF,MAAM,WAAW,GAAG,CAAC,IAAa,EAAE,EAAE,CACpC,UAAU,CAAC,GAAG,EAAE;QACd,MAAM,qBAAqB,GAAG,MAAM,CAAC,WAAW,CAC9C,oBAAoB,EAAE,IAAI,cAAc,EAAE,EAC1C;YACE,cAAc,EAAE,KAAK;SACtB,CACF,CAAA;QAED,MAAM,mBAAmB,GAAG,IAAI,CAAC,qBAAqB,CAAC,CAAA;QAEvD,OAAO,CACL,IAAI;YACJ,mBAAmB,EAAE,QAAQ;YAC7B,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,CAAE,CAAC,QAAQ,CAC7C,CAAA;IACH,CAAC,CAAC,CAAA;IAEJ,OAAO;QACL,cAAc;QACd,WAAW;QACX,iBAAiB,EAAE,uBAAuB;KAC3C,CAAA;AACH,CAAC"}
|