@tanstack/react-router 0.0.1-beta.263 → 0.0.1-beta.265
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/build/cjs/Matches.js.map +1 -1
- package/build/cjs/index.js +1 -0
- package/build/cjs/index.js.map +1 -1
- package/build/cjs/route.js +39 -0
- package/build/cjs/route.js.map +1 -1
- package/build/cjs/router.js +2 -0
- package/build/cjs/router.js.map +1 -1
- package/build/esm/index.js +41 -1
- package/build/esm/index.js.map +1 -1
- package/build/stats-html.html +1 -1
- package/build/stats-react.json +355 -355
- package/build/types/Matches.d.ts +2 -1
- package/build/types/route.d.ts +23 -2
- package/build/umd/index.development.js +41 -0
- package/build/umd/index.development.js.map +1 -1
- package/build/umd/index.production.js +1 -1
- package/build/umd/index.production.js.map +1 -1
- package/package.json +2 -2
- package/src/Matches.tsx +2 -1
- package/src/route.ts +58 -2
- package/src/router.ts +5 -2
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.
|
|
4
|
+
"version": "0.0.1-beta.265",
|
|
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.
|
|
47
|
+
"@tanstack/history": "0.0.1-beta.265"
|
|
48
48
|
},
|
|
49
49
|
"scripts": {
|
|
50
50
|
"build": "rollup --config rollup.config.js"
|
package/src/Matches.tsx
CHANGED
|
@@ -37,6 +37,7 @@ export interface RouteMatch<
|
|
|
37
37
|
loadPromise?: Promise<void>
|
|
38
38
|
loaderData?: RouteById<TRouteTree, TRouteId>['types']['loaderData']
|
|
39
39
|
__resolveLoadPromise?: () => void
|
|
40
|
+
routeContext: RouteById<TRouteTree, TRouteId>['types']['routeContext']
|
|
40
41
|
context: RouteById<TRouteTree, TRouteId>['types']['allContext']
|
|
41
42
|
search: FullSearchSchema<TRouteTree> &
|
|
42
43
|
RouteById<TRouteTree, TRouteId>['types']['fullSearchSchema']
|
|
@@ -411,7 +412,7 @@ export function useLoaderData<
|
|
|
411
412
|
TRouteTree,
|
|
412
413
|
TFrom
|
|
413
414
|
>,
|
|
414
|
-
TSelected = TRouteMatch['loaderData'],
|
|
415
|
+
TSelected = Required<TRouteMatch>['loaderData'],
|
|
415
416
|
>(
|
|
416
417
|
opts: StrictOrFrom<TFrom> & {
|
|
417
418
|
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 => {
|
package/src/router.ts
CHANGED
|
@@ -667,6 +667,7 @@ export class Router<
|
|
|
667
667
|
error: undefined,
|
|
668
668
|
paramsError: parseErrors[index],
|
|
669
669
|
loadPromise: Promise.resolve(),
|
|
670
|
+
routeContext: undefined!,
|
|
670
671
|
context: undefined!,
|
|
671
672
|
abortController: new AbortController(),
|
|
672
673
|
shouldReloadDeps: undefined,
|
|
@@ -997,8 +998,6 @@ export class Router<
|
|
|
997
998
|
}))
|
|
998
999
|
}
|
|
999
1000
|
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
1001
|
// Check each match middleware to see if the route can be accessed
|
|
1003
1002
|
try {
|
|
1004
1003
|
for (let [index, match] of matches.entries()) {
|
|
@@ -1071,6 +1070,10 @@ export class Router<
|
|
|
1071
1070
|
|
|
1072
1071
|
matches[index] = match = {
|
|
1073
1072
|
...match,
|
|
1073
|
+
routeContext: replaceEqualDeep(
|
|
1074
|
+
match.routeContext,
|
|
1075
|
+
beforeLoadContext,
|
|
1076
|
+
),
|
|
1074
1077
|
context: replaceEqualDeep(match.context, context),
|
|
1075
1078
|
abortController,
|
|
1076
1079
|
}
|