@tanstack/react-router 0.0.1-beta.263 → 0.0.1-beta.264

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tanstack/react-router",
3
3
  "author": "Tanner Linsley",
4
- "version": "0.0.1-beta.263",
4
+ "version": "0.0.1-beta.264",
5
5
  "license": "MIT",
6
6
  "repository": "tanstack/router",
7
7
  "homepage": "https://tanstack.com/router",
@@ -44,7 +44,7 @@
44
44
  "@tanstack/store": "^0.1.3",
45
45
  "tiny-invariant": "^1.3.1",
46
46
  "tiny-warning": "^1.0.3",
47
- "@tanstack/history": "0.0.1-beta.263"
47
+ "@tanstack/history": "0.0.1-beta.264"
48
48
  },
49
49
  "scripts": {
50
50
  "build": "rollup --config rollup.config.js"
package/src/Matches.tsx CHANGED
@@ -411,7 +411,7 @@ export function useLoaderData<
411
411
  TRouteTree,
412
412
  TFrom
413
413
  >,
414
- TSelected = TRouteMatch['loaderData'],
414
+ TSelected = Required<TRouteMatch>['loaderData'],
415
415
  >(
416
416
  opts: StrictOrFrom<TFrom> & {
417
417
  select?: (match: TRouteMatch) => TSelected
package/src/route.ts CHANGED
@@ -6,8 +6,8 @@ import { AnyRouteMatch } from './Matches'
6
6
  import { NavigateOptions, ParsePathParams, ToSubOptions } from './link'
7
7
  import { ParsedLocation } from './location'
8
8
  import { joinPaths, trimPath } from './path'
9
- import { RoutePaths } from './routeInfo'
10
- import { AnyRouter } from './router'
9
+ import { RouteById, RouteIds, RoutePaths } from './routeInfo'
10
+ import { AnyRouter, RegisteredRouter } from './router'
11
11
  import { useParams } from './useParams'
12
12
  import { useSearch } from './useSearch'
13
13
  import {
@@ -371,6 +371,58 @@ export type RouteConstraints = {
371
371
  TRouteTree: AnyRoute
372
372
  }
373
373
 
374
+ export class RouteApi<
375
+ TId extends RouteIds<RegisteredRouter['routeTree']>,
376
+ TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,
377
+ TFullSearchSchema extends Record<
378
+ string,
379
+ any
380
+ > = TRoute['types']['fullSearchSchema'],
381
+ TAllParams extends AnyPathParams = TRoute['types']['allParams'],
382
+ TAllContext extends Record<string, any> = TRoute['types']['allContext'],
383
+ TLoaderData extends any = TRoute['types']['loaderData'],
384
+ > {
385
+ id: TId
386
+
387
+ constructor({ id }: { id: TId }) {
388
+ this.id = id as any
389
+ }
390
+
391
+ useMatch = <TSelected = TAllContext>(opts?: {
392
+ select?: (search: TAllContext) => TSelected
393
+ }): TSelected => {
394
+ return useMatch({ ...opts, from: this.id }) as any
395
+ }
396
+
397
+ useRouteContext = <TSelected = TAllContext>(opts?: {
398
+ select?: (search: TAllContext) => TSelected
399
+ }): TSelected => {
400
+ return useMatch({
401
+ ...opts,
402
+ from: this.id,
403
+ select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
404
+ } as any)
405
+ }
406
+
407
+ useSearch = <TSelected = TFullSearchSchema>(opts?: {
408
+ select?: (search: TFullSearchSchema) => TSelected
409
+ }): TSelected => {
410
+ return useSearch({ ...opts, from: this.id } as any)
411
+ }
412
+
413
+ useParams = <TSelected = TAllParams>(opts?: {
414
+ select?: (search: TAllParams) => TSelected
415
+ }): TSelected => {
416
+ return useParams({ ...opts, from: this.id } as any)
417
+ }
418
+
419
+ useLoaderData = <TSelected = TLoaderData>(opts?: {
420
+ select?: (search: TLoaderData) => TSelected
421
+ }): TSelected => {
422
+ return useLoaderData({ ...opts, from: this.id } as any) as any
423
+ }
424
+ }
425
+
374
426
  export class Route<
375
427
  TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
376
428
  TPath extends RouteConstraints['TPath'] = '/',
@@ -590,6 +642,7 @@ export class Route<
590
642
  }): TSelected => {
591
643
  return useMatch({ ...opts, from: this.id }) as any
592
644
  }
645
+
593
646
  useRouteContext = <TSelected = TAllContext>(opts?: {
594
647
  select?: (search: TAllContext) => TSelected
595
648
  }): TSelected => {
@@ -599,16 +652,19 @@ export class Route<
599
652
  select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),
600
653
  } as any)
601
654
  }
655
+
602
656
  useSearch = <TSelected = TFullSearchSchema>(opts?: {
603
657
  select?: (search: TFullSearchSchema) => TSelected
604
658
  }): TSelected => {
605
659
  return useSearch({ ...opts, from: this.id } as any)
606
660
  }
661
+
607
662
  useParams = <TSelected = TAllParams>(opts?: {
608
663
  select?: (search: TAllParams) => TSelected
609
664
  }): TSelected => {
610
665
  return useParams({ ...opts, from: this.id } as any)
611
666
  }
667
+
612
668
  useLoaderData = <TSelected = TLoaderData>(opts?: {
613
669
  select?: (search: TLoaderData) => TSelected
614
670
  }): TSelected => {