@tanstack/solid-router 1.132.0-alpha.4 → 1.132.0

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.
Files changed (94) hide show
  1. package/dist/cjs/Asset.cjs +30 -1
  2. package/dist/cjs/Asset.cjs.map +1 -1
  3. package/dist/cjs/Matches.cjs +22 -18
  4. package/dist/cjs/Matches.cjs.map +1 -1
  5. package/dist/cjs/RouterProvider.cjs +9 -9
  6. package/dist/cjs/RouterProvider.cjs.map +1 -1
  7. package/dist/cjs/ScriptOnce.cjs +12 -2
  8. package/dist/cjs/ScriptOnce.cjs.map +1 -1
  9. package/dist/cjs/fileRoute.cjs.map +1 -1
  10. package/dist/cjs/fileRoute.d.cts +3 -3
  11. package/dist/cjs/index.cjs +8 -4
  12. package/dist/cjs/index.cjs.map +1 -1
  13. package/dist/cjs/index.d.cts +4 -2
  14. package/dist/cjs/link.cjs +51 -32
  15. package/dist/cjs/link.cjs.map +1 -1
  16. package/dist/cjs/route.cjs.map +1 -1
  17. package/dist/cjs/route.d.cts +11 -11
  18. package/dist/cjs/router.cjs.map +1 -1
  19. package/dist/cjs/router.d.cts +2 -2
  20. package/dist/cjs/ssr/renderRouterToString.cjs +1 -0
  21. package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -1
  22. package/dist/cjs/useBlocker.cjs +1 -1
  23. package/dist/cjs/useBlocker.cjs.map +1 -1
  24. package/dist/cjs/useNavigate.cjs +3 -11
  25. package/dist/cjs/useNavigate.cjs.map +1 -1
  26. package/dist/cjs/useParams.cjs +3 -2
  27. package/dist/cjs/useParams.cjs.map +1 -1
  28. package/dist/esm/Asset.js +30 -1
  29. package/dist/esm/Asset.js.map +1 -1
  30. package/dist/esm/Matches.js +16 -12
  31. package/dist/esm/Matches.js.map +1 -1
  32. package/dist/esm/RouterProvider.js +9 -9
  33. package/dist/esm/RouterProvider.js.map +1 -1
  34. package/dist/esm/ScriptOnce.js +13 -3
  35. package/dist/esm/ScriptOnce.js.map +1 -1
  36. package/dist/esm/fileRoute.d.ts +3 -3
  37. package/dist/esm/fileRoute.js.map +1 -1
  38. package/dist/esm/index.d.ts +4 -2
  39. package/dist/esm/index.js +3 -2
  40. package/dist/esm/link.js +51 -32
  41. package/dist/esm/link.js.map +1 -1
  42. package/dist/esm/route.d.ts +11 -11
  43. package/dist/esm/route.js.map +1 -1
  44. package/dist/esm/router.d.ts +2 -2
  45. package/dist/esm/router.js.map +1 -1
  46. package/dist/esm/ssr/renderRouterToString.js +1 -0
  47. package/dist/esm/ssr/renderRouterToString.js.map +1 -1
  48. package/dist/esm/useBlocker.js +1 -1
  49. package/dist/esm/useBlocker.js.map +1 -1
  50. package/dist/esm/useNavigate.js +3 -11
  51. package/dist/esm/useNavigate.js.map +1 -1
  52. package/dist/esm/useParams.js +3 -2
  53. package/dist/esm/useParams.js.map +1 -1
  54. package/dist/source/Asset.jsx +33 -1
  55. package/dist/source/Asset.jsx.map +1 -1
  56. package/dist/source/Matches.jsx +11 -7
  57. package/dist/source/Matches.jsx.map +1 -1
  58. package/dist/source/RouterProvider.jsx +7 -7
  59. package/dist/source/RouterProvider.jsx.map +1 -1
  60. package/dist/source/ScriptOnce.jsx +4 -2
  61. package/dist/source/ScriptOnce.jsx.map +1 -1
  62. package/dist/source/fileRoute.d.ts +3 -3
  63. package/dist/source/fileRoute.js.map +1 -1
  64. package/dist/source/index.d.ts +4 -2
  65. package/dist/source/index.jsx +2 -1
  66. package/dist/source/index.jsx.map +1 -1
  67. package/dist/source/link.jsx +52 -42
  68. package/dist/source/link.jsx.map +1 -1
  69. package/dist/source/route.d.ts +11 -11
  70. package/dist/source/route.jsx.map +1 -1
  71. package/dist/source/router.d.ts +2 -2
  72. package/dist/source/router.js.map +1 -1
  73. package/dist/source/ssr/renderRouterToString.jsx +1 -0
  74. package/dist/source/ssr/renderRouterToString.jsx.map +1 -1
  75. package/dist/source/useBlocker.jsx +1 -1
  76. package/dist/source/useBlocker.jsx.map +1 -1
  77. package/dist/source/useNavigate.jsx +3 -10
  78. package/dist/source/useNavigate.jsx.map +1 -1
  79. package/dist/source/useParams.jsx +3 -2
  80. package/dist/source/useParams.jsx.map +1 -1
  81. package/package.json +3 -3
  82. package/src/Asset.tsx +47 -1
  83. package/src/Matches.tsx +18 -16
  84. package/src/RouterProvider.tsx +9 -10
  85. package/src/ScriptOnce.tsx +5 -2
  86. package/src/fileRoute.ts +17 -2
  87. package/src/index.tsx +7 -4
  88. package/src/link.tsx +52 -46
  89. package/src/route.tsx +101 -17
  90. package/src/router.ts +2 -5
  91. package/src/ssr/renderRouterToString.tsx +1 -0
  92. package/src/useBlocker.tsx +1 -1
  93. package/src/useNavigate.tsx +3 -12
  94. package/src/useParams.tsx +6 -4
package/src/route.tsx CHANGED
@@ -20,6 +20,7 @@ import type {
20
20
  ErrorComponentProps,
21
21
  NotFoundError,
22
22
  NotFoundRouteProps,
23
+ Register,
23
24
  RegisteredRouter,
24
25
  ResolveFullPath,
25
26
  ResolveId,
@@ -152,6 +153,7 @@ export class RouteApi<
152
153
  }
153
154
 
154
155
  export class Route<
156
+ in out TRegister = unknown,
155
157
  in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
156
158
  in out TPath extends RouteConstraints['TPath'] = '/',
157
159
  in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
@@ -173,8 +175,12 @@ export class Route<
173
175
  in out TLoaderFn = undefined,
174
176
  in out TChildren = unknown,
175
177
  in out TFileRouteTypes = unknown,
178
+ in out TSSR = unknown,
179
+ in out TMiddlewares = unknown,
180
+ in out THandlers = undefined,
176
181
  >
177
182
  extends BaseRoute<
183
+ TRegister,
178
184
  TParentRoute,
179
185
  TPath,
180
186
  TFullPath,
@@ -188,10 +194,14 @@ export class Route<
188
194
  TLoaderDeps,
189
195
  TLoaderFn,
190
196
  TChildren,
191
- TFileRouteTypes
197
+ TFileRouteTypes,
198
+ TSSR,
199
+ TMiddlewares,
200
+ THandlers
192
201
  >
193
202
  implements
194
203
  RouteCore<
204
+ TRegister,
195
205
  TParentRoute,
196
206
  TPath,
197
207
  TFullPath,
@@ -205,7 +215,10 @@ export class Route<
205
215
  TLoaderDeps,
206
216
  TLoaderFn,
207
217
  TChildren,
208
- TFileRouteTypes
218
+ TFileRouteTypes,
219
+ TSSR,
220
+ TMiddlewares,
221
+ THandlers
209
222
  >
210
223
  {
211
224
  /**
@@ -213,6 +226,7 @@ export class Route<
213
226
  */
214
227
  constructor(
215
228
  options?: RouteOptions<
229
+ TRegister,
216
230
  TParentRoute,
217
231
  TId,
218
232
  TCustomId,
@@ -224,7 +238,10 @@ export class Route<
224
238
  TLoaderFn,
225
239
  TRouterContext,
226
240
  TRouteContextFn,
227
- TBeforeLoadFn
241
+ TBeforeLoadFn,
242
+ TSSR,
243
+ TMiddlewares,
244
+ THandlers
228
245
  >,
229
246
  ) {
230
247
  super(options)
@@ -277,6 +294,7 @@ export class Route<
277
294
  }
278
295
 
279
296
  export function createRoute<
297
+ TRegister = unknown,
280
298
  TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
281
299
  TPath extends RouteConstraints['TPath'] = '/',
282
300
  TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
@@ -296,8 +314,11 @@ export function createRoute<
296
314
  TLoaderDeps extends Record<string, any> = {},
297
315
  TLoaderFn = undefined,
298
316
  TChildren = unknown,
317
+ TSSR = unknown,
318
+ THandlers = undefined,
299
319
  >(
300
320
  options: RouteOptions<
321
+ TRegister,
301
322
  TParentRoute,
302
323
  TId,
303
324
  TCustomId,
@@ -309,9 +330,12 @@ export function createRoute<
309
330
  TLoaderFn,
310
331
  AnyContext,
311
332
  TRouteContextFn,
312
- TBeforeLoadFn
333
+ TBeforeLoadFn,
334
+ TSSR,
335
+ THandlers
313
336
  >,
314
337
  ): Route<
338
+ TRegister,
315
339
  TParentRoute,
316
340
  TPath,
317
341
  TFullPath,
@@ -325,9 +349,12 @@ export function createRoute<
325
349
  TLoaderDeps,
326
350
  TLoaderFn,
327
351
  TChildren,
328
- unknown
352
+ unknown,
353
+ TSSR,
354
+ THandlers
329
355
  > {
330
356
  return new Route<
357
+ TRegister,
331
358
  TParentRoute,
332
359
  TPath,
333
360
  TFullPath,
@@ -341,36 +368,58 @@ export function createRoute<
341
368
  TLoaderDeps,
342
369
  TLoaderFn,
343
370
  TChildren,
344
- unknown
371
+ unknown,
372
+ TSSR,
373
+ THandlers
345
374
  >(options)
346
375
  }
347
376
 
348
- export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>
377
+ export type AnyRootRoute = RootRoute<
378
+ any,
379
+ any,
380
+ any,
381
+ any,
382
+ any,
383
+ any,
384
+ any,
385
+ any,
386
+ any,
387
+ any
388
+ >
349
389
 
350
390
  export function createRootRouteWithContext<TRouterContext extends {}>() {
351
391
  return <
392
+ TRegister = Register,
352
393
  TRouteContextFn = AnyContext,
353
394
  TBeforeLoadFn = AnyContext,
354
395
  TSearchValidator = undefined,
355
396
  TLoaderDeps extends Record<string, any> = {},
356
397
  TLoaderFn = undefined,
398
+ TSSR = unknown,
399
+ THandlers = undefined,
357
400
  >(
358
401
  options?: RootRouteOptions<
402
+ TRegister,
359
403
  TSearchValidator,
360
404
  TRouterContext,
361
405
  TRouteContextFn,
362
406
  TBeforeLoadFn,
363
407
  TLoaderDeps,
364
- TLoaderFn
408
+ TLoaderFn,
409
+ TSSR,
410
+ THandlers
365
411
  >,
366
412
  ) => {
367
413
  return createRootRoute<
414
+ TRegister,
368
415
  TSearchValidator,
369
416
  TRouterContext,
370
417
  TRouteContextFn,
371
418
  TBeforeLoadFn,
372
419
  TLoaderDeps,
373
- TLoaderFn
420
+ TLoaderFn,
421
+ TSSR,
422
+ THandlers
374
423
  >(options as any)
375
424
  }
376
425
  }
@@ -381,6 +430,7 @@ export function createRootRouteWithContext<TRouterContext extends {}>() {
381
430
  export const rootRouteWithContext = createRootRouteWithContext
382
431
 
383
432
  export class RootRoute<
433
+ in out TRegister = Register,
384
434
  in out TSearchValidator = undefined,
385
435
  in out TRouterContext = {},
386
436
  in out TRouteContextFn = AnyContext,
@@ -389,8 +439,11 @@ export class RootRoute<
389
439
  in out TLoaderFn = undefined,
390
440
  in out TChildren = unknown,
391
441
  in out TFileRouteTypes = unknown,
442
+ in out TSSR = unknown,
443
+ in out THandlers = undefined,
392
444
  >
393
445
  extends BaseRootRoute<
446
+ TRegister,
394
447
  TSearchValidator,
395
448
  TRouterContext,
396
449
  TRouteContextFn,
@@ -398,10 +451,13 @@ export class RootRoute<
398
451
  TLoaderDeps,
399
452
  TLoaderFn,
400
453
  TChildren,
401
- TFileRouteTypes
454
+ TFileRouteTypes,
455
+ TSSR,
456
+ THandlers
402
457
  >
403
458
  implements
404
459
  RootRouteCore<
460
+ TRegister,
405
461
  TSearchValidator,
406
462
  TRouterContext,
407
463
  TRouteContextFn,
@@ -409,7 +465,9 @@ export class RootRoute<
409
465
  TLoaderDeps,
410
466
  TLoaderFn,
411
467
  TChildren,
412
- TFileRouteTypes
468
+ TFileRouteTypes,
469
+ TSSR,
470
+ THandlers
413
471
  >
414
472
  {
415
473
  /**
@@ -417,12 +475,15 @@ export class RootRoute<
417
475
  */
418
476
  constructor(
419
477
  options?: RootRouteOptions<
478
+ TRegister,
420
479
  TSearchValidator,
421
480
  TRouterContext,
422
481
  TRouteContextFn,
423
482
  TBeforeLoadFn,
424
483
  TLoaderDeps,
425
- TLoaderFn
484
+ TLoaderFn,
485
+ TSSR,
486
+ THandlers
426
487
  >,
427
488
  ) {
428
489
  super(options)
@@ -504,6 +565,7 @@ export type ErrorRouteComponent = AsyncRouteComponent<ErrorComponentProps>
504
565
  export type NotFoundRouteComponent = RouteTypes<NotFoundRouteProps>['component']
505
566
 
506
567
  export class NotFoundRoute<
568
+ TRegister,
507
569
  TParentRoute extends AnyRootRoute,
508
570
  TRouterContext = AnyContext,
509
571
  TRouteContextFn = AnyContext,
@@ -512,7 +574,10 @@ export class NotFoundRoute<
512
574
  TLoaderDeps extends Record<string, any> = {},
513
575
  TLoaderFn = undefined,
514
576
  TChildren = unknown,
577
+ TSSR = unknown,
578
+ THandlers = undefined,
515
579
  > extends Route<
580
+ TRegister,
516
581
  TParentRoute,
517
582
  '/404',
518
583
  '/404',
@@ -525,11 +590,14 @@ export class NotFoundRoute<
525
590
  TBeforeLoadFn,
526
591
  TLoaderDeps,
527
592
  TLoaderFn,
528
- TChildren
593
+ TChildren,
594
+ TSSR,
595
+ THandlers
529
596
  > {
530
597
  constructor(
531
598
  options: Omit<
532
599
  RouteOptions<
600
+ TRegister,
533
601
  TParentRoute,
534
602
  string,
535
603
  string,
@@ -541,7 +609,9 @@ export class NotFoundRoute<
541
609
  TLoaderFn,
542
610
  TRouterContext,
543
611
  TRouteContextFn,
544
- TBeforeLoadFn
612
+ TBeforeLoadFn,
613
+ TSSR,
614
+ THandlers
545
615
  >,
546
616
  | 'caseSensitive'
547
617
  | 'parseParams'
@@ -559,22 +629,29 @@ export class NotFoundRoute<
559
629
  }
560
630
 
561
631
  export function createRootRoute<
632
+ TRegister = Register,
562
633
  TSearchValidator = undefined,
563
634
  TRouterContext = {},
564
635
  TRouteContextFn = AnyContext,
565
636
  TBeforeLoadFn = AnyContext,
566
637
  TLoaderDeps extends Record<string, any> = {},
567
638
  TLoaderFn = undefined,
639
+ TSSR = unknown,
640
+ THandlers = undefined,
568
641
  >(
569
642
  options?: RootRouteOptions<
643
+ TRegister,
570
644
  TSearchValidator,
571
645
  TRouterContext,
572
646
  TRouteContextFn,
573
647
  TBeforeLoadFn,
574
648
  TLoaderDeps,
575
- TLoaderFn
649
+ TLoaderFn,
650
+ TSSR,
651
+ THandlers
576
652
  >,
577
653
  ): RootRoute<
654
+ TRegister,
578
655
  TSearchValidator,
579
656
  TRouterContext,
580
657
  TRouteContextFn,
@@ -582,14 +659,21 @@ export function createRootRoute<
582
659
  TLoaderDeps,
583
660
  TLoaderFn,
584
661
  unknown,
585
- unknown
662
+ unknown,
663
+ TSSR,
664
+ THandlers
586
665
  > {
587
666
  return new RootRoute<
667
+ TRegister,
588
668
  TSearchValidator,
589
669
  TRouterContext,
590
670
  TRouteContextFn,
591
671
  TBeforeLoadFn,
592
672
  TLoaderDeps,
593
- TLoaderFn
673
+ TLoaderFn,
674
+ unknown,
675
+ unknown,
676
+ TSSR,
677
+ THandlers
594
678
  >(options)
595
679
  }
package/src/router.ts CHANGED
@@ -83,14 +83,12 @@ export class Router<
83
83
  in out TDefaultStructuralSharingOption extends boolean = false,
84
84
  in out TRouterHistory extends RouterHistory = RouterHistory,
85
85
  in out TDehydrated extends Record<string, any> = Record<string, any>,
86
- in out TTransformerConfig = any,
87
86
  > extends RouterCore<
88
87
  TRouteTree,
89
88
  TTrailingSlashOption,
90
89
  TDefaultStructuralSharingOption,
91
90
  TRouterHistory,
92
- TDehydrated,
93
- TTransformerConfig
91
+ TDehydrated
94
92
  > {
95
93
  constructor(
96
94
  options: RouterConstructorOptions<
@@ -98,8 +96,7 @@ export class Router<
98
96
  TTrailingSlashOption,
99
97
  TDefaultStructuralSharingOption,
100
98
  TRouterHistory,
101
- TDehydrated,
102
- TTransformerConfig
99
+ TDehydrated
103
100
  >,
104
101
  ) {
105
102
  super(options)
@@ -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
  )
@@ -185,7 +185,7 @@ export function useBlocker(
185
185
  function getLocation(
186
186
  location: HistoryLocation,
187
187
  ): AnyShouldBlockFnLocation {
188
- const parsedLocation = router.parseLocation(undefined, location)
188
+ const parsedLocation = router.parseLocation(location)
189
189
  const matchedRoutes = router.getMatchedRoutes(
190
190
  parsedLocation.pathname,
191
191
  undefined,
@@ -1,6 +1,5 @@
1
1
  import * as Solid from 'solid-js'
2
2
  import { useRouter } from './useRouter'
3
- import { useMatch } from './useMatch'
4
3
  import type {
5
4
  AnyRouter,
6
5
  FromPathOption,
@@ -15,20 +14,12 @@ export function useNavigate<
15
14
  >(_defaultOpts?: {
16
15
  from?: FromPathOption<TRouter, TDefaultFrom>
17
16
  }): UseNavigateResult<TDefaultFrom> {
18
- const { navigate, state } = useRouter()
19
-
20
- const matchIndex = useMatch({
21
- strict: false,
22
- select: (match) => match.index,
23
- })
17
+ const router = useRouter()
24
18
 
25
19
  return ((options: NavigateOptions) => {
26
- return navigate({
20
+ return router.navigate({
27
21
  ...options,
28
- from:
29
- options.from ??
30
- _defaultOpts?.from ??
31
- state.matches[matchIndex()]!.fullPath,
22
+ from: options.from ?? _defaultOpts?.from,
32
23
  })
33
24
  }) as UseNavigateResult<TDefaultFrom>
34
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
- select: (match: any) => {
68
- return opts.select ? opts.select(match.params) : match.params
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
- } as any) as any
72
+ }) as Accessor<any>
71
73
  }