@tanstack/react-router 1.32.16 → 1.32.17
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/Matches.cjs +7 -36
- package/dist/cjs/Matches.cjs.map +1 -1
- package/dist/cjs/Matches.d.cts +2 -11
- package/dist/cjs/fileRoute.cjs +7 -5
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/index.cjs +8 -4
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.cts +6 -2
- package/dist/cjs/link.cjs +2 -2
- package/dist/cjs/link.cjs.map +1 -1
- package/dist/cjs/root.cjs +5 -0
- package/dist/cjs/root.cjs.map +1 -0
- package/dist/cjs/root.d.cts +2 -0
- package/dist/cjs/route.cjs +19 -18
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +1 -2
- package/dist/cjs/router.cjs +56 -52
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/useLoaderData.cjs +13 -0
- package/dist/cjs/useLoaderData.cjs.map +1 -0
- package/dist/cjs/useLoaderData.d.cts +9 -0
- package/dist/cjs/useLoaderDeps.cjs +13 -0
- package/dist/cjs/useLoaderDeps.cjs.map +1 -0
- package/dist/cjs/useLoaderDeps.d.cts +9 -0
- package/dist/cjs/useMatch.cjs +41 -0
- package/dist/cjs/useMatch.cjs.map +1 -0
- package/dist/cjs/useMatch.d.cts +9 -0
- package/dist/cjs/useNavigate.cjs +2 -2
- package/dist/cjs/useNavigate.cjs.map +1 -1
- package/dist/cjs/useParams.cjs +2 -2
- package/dist/cjs/useParams.cjs.map +1 -1
- package/dist/cjs/useRouteContext.cjs +2 -2
- package/dist/cjs/useRouteContext.cjs.map +1 -1
- package/dist/cjs/useSearch.cjs +2 -2
- package/dist/cjs/useSearch.cjs.map +1 -1
- package/dist/esm/Matches.d.ts +2 -11
- package/dist/esm/Matches.js +7 -36
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/fileRoute.js +3 -1
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +6 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/link.js +1 -1
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/root.d.ts +2 -0
- package/dist/esm/root.js +5 -0
- package/dist/esm/root.js.map +1 -0
- package/dist/esm/route.d.ts +1 -2
- package/dist/esm/route.js +4 -3
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.js +7 -3
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/useLoaderData.d.ts +9 -0
- package/dist/esm/useLoaderData.js +13 -0
- package/dist/esm/useLoaderData.js.map +1 -0
- package/dist/esm/useLoaderDeps.d.ts +9 -0
- package/dist/esm/useLoaderDeps.js +13 -0
- package/dist/esm/useLoaderDeps.js.map +1 -0
- package/dist/esm/useMatch.d.ts +9 -0
- package/dist/esm/useMatch.js +24 -0
- package/dist/esm/useMatch.js.map +1 -0
- package/dist/esm/useNavigate.js +1 -1
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.js +1 -1
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.js +1 -1
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useSearch.js +1 -1
- package/dist/esm/useSearch.js.map +1 -1
- package/package.json +1 -1
- package/src/Matches.tsx +20 -88
- package/src/fileRoute.ts +4 -2
- package/src/index.tsx +4 -5
- package/src/link.tsx +1 -1
- package/src/root.ts +2 -0
- package/src/route.ts +5 -3
- package/src/router.ts +7 -4
- package/src/useLoaderData.tsx +29 -0
- package/src/useLoaderDeps.tsx +29 -0
- package/src/useMatch.tsx +40 -0
- package/src/useNavigate.tsx +1 -1
- package/src/useParams.tsx +1 -1
- package/src/useRouteContext.ts +1 -1
- package/src/useSearch.tsx +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './
|
|
1
|
+
{"version":3,"file":"useNavigate.js","sources":["../../src/useNavigate.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useMatch } from './useMatch'\nimport { useRouter } from './useRouter'\n\nimport type { FromPathOption, NavigateOptions } from './link'\nimport type { RoutePaths } from './routeInfo'\nimport type { AnyRouter, RegisteredRouter } from './router'\n\nexport type UseNavigateResult<TDefaultFrom extends string> = <\n TTo extends string,\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = TDefaultFrom,\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>({\n from,\n ...rest\n}: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => Promise<void>\n\nexport function useNavigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TDefaultFrom extends string = string,\n>(_defaultOpts?: {\n from?: FromPathOption<TRouter, TDefaultFrom>\n}): UseNavigateResult<TDefaultFrom> {\n const router = useRouter()\n\n return React.useCallback(\n (options: NavigateOptions) => {\n return router.navigate({\n ...options,\n from: options.to ? router.state.resolvedLocation.pathname : undefined,\n })\n },\n [router],\n ) as UseNavigateResult<TDefaultFrom>\n}\n\n// NOTE: I don't know of anyone using this. It's undocumented, so let's wait until someone needs it\n// export function typedNavigate<\n// TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n// TDefaultFrom extends RoutePaths<TRouteTree> = '/',\n// >(navigate: (opts: NavigateOptions<any>) => Promise<void>) {\n// return navigate as <\n// TFrom extends RoutePaths<TRouteTree> = TDefaultFrom,\n// TTo extends string = '',\n// TMaskFrom extends RoutePaths<TRouteTree> = '/',\n// TMaskTo extends string = '',\n// >(\n// opts?: NavigateOptions<TRouteTree, TFrom, TTo, TMaskFrom, TMaskTo>,\n// ) => Promise<void>\n// } //\n\nexport function Navigate<\n TRouter extends AnyRouter = RegisteredRouter,\n TFrom extends RoutePaths<TRouter['routeTree']> | string = string,\n TTo extends string = '',\n TMaskFrom extends RoutePaths<TRouter['routeTree']> | string = TFrom,\n TMaskTo extends string = '',\n>(props: NavigateOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): null {\n const { navigate } = useRouter()\n const match = useMatch({ strict: false })\n\n React.useEffect(() => {\n navigate({\n from: props.to ? match.pathname : undefined,\n ...props,\n } as any)\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [])\n\n return null\n}\n"],"names":[],"mappings":";;;AAmBO,SAAS,YAGd,cAEkC;AAClC,QAAM,SAAS;AAEf,SAAO,MAAM;AAAA,IACX,CAAC,YAA6B;AAC5B,aAAO,OAAO,SAAS;AAAA,QACrB,GAAG;AAAA,QACH,MAAM,QAAQ,KAAK,OAAO,MAAM,iBAAiB,WAAW;AAAA,MAAA,CAC7D;AAAA,IACH;AAAA,IACA,CAAC,MAAM;AAAA,EAAA;AAEX;AAiBO,SAAS,SAMd,OAAuE;AACjE,QAAA,EAAE,aAAa;AACrB,QAAM,QAAQ,SAAS,EAAE,QAAQ,MAAO,CAAA;AAExC,QAAM,UAAU,MAAM;AACX,aAAA;AAAA,MACP,MAAM,MAAM,KAAK,MAAM,WAAW;AAAA,MAClC,GAAG;AAAA,IAAA,CACG;AAAA,EAEV,GAAG,CAAE,CAAA;AAEE,SAAA;AACT;"}
|
package/dist/esm/useParams.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useParams.js","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './
|
|
1
|
+
{"version":3,"file":"useParams.js","sources":["../../src/useParams.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute } from './route'\nimport type { AllParams, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { Expand } from './utils'\nimport type { StrictOrFrom } from './utils'\n\nexport function useParams<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TReturnIntersection extends boolean = false,\n TParams = TReturnIntersection extends false\n ? RouteById<TRouteTree, TFrom>['types']['allParams']\n : Expand<Partial<AllParams<TRouteTree>>>,\n TSelected = TParams,\n>(\n opts: StrictOrFrom<TFrom, TReturnIntersection> & {\n select?: (params: TParams) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (match) => {\n return opts.select ? opts.select(match.params as TParams) : match.params\n },\n }) as TSelected\n}\n"],"names":[],"mappings":";AAOO,SAAS,UASd,MAGW;AACX,SAAO,SAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAAU;AACjB,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAiB,IAAI,MAAM;AAAA,IACpE;AAAA,EAAA,CACD;AACH;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRouteContext.js","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './
|
|
1
|
+
{"version":3,"file":"useRouteContext.js","sources":["../../src/useRouteContext.ts"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { MakeRouteMatch } from './Matches'\nimport type { AnyRoute } from './route'\nimport type { RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { StrictOrFrom } from './utils'\n\nexport function useRouteContext<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TRouteContext = RouteById<TRouteTree, TFrom>['types']['allContext'],\n TSelected = TRouteContext,\n>(\n opts: StrictOrFrom<TFrom> & {\n select?: (search: TRouteContext) => TSelected\n },\n): TSelected {\n return useMatch({\n ...(opts as any),\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) =>\n opts.select ? opts.select(match.context) : match.context,\n })\n}\n"],"names":[],"mappings":";AAOO,SAAS,gBAMd,MAGW;AACX,SAAO,SAAS;AAAA,IACd,GAAI;AAAA,IACJ,QAAQ,CAAC,UACP,KAAK,SAAS,KAAK,OAAO,MAAM,OAAO,IAAI,MAAM;AAAA,EAAA,CACpD;AACH;"}
|
package/dist/esm/useSearch.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './
|
|
1
|
+
{"version":3,"file":"useSearch.js","sources":["../../src/useSearch.tsx"],"sourcesContent":["import { useMatch } from './useMatch'\nimport type { AnyRoute, RootSearchSchema } from './route'\nimport type { FullSearchSchema, RouteById, RouteIds } from './routeInfo'\nimport type { RegisteredRouter } from './router'\nimport type { MakeRouteMatch } from './Matches'\nimport type { StrictOrFrom } from './utils'\n\nexport function useSearch<\n TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],\n TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,\n TReturnIntersection extends boolean = false,\n TSearch = TReturnIntersection extends false\n ? Exclude<\n RouteById<TRouteTree, TFrom>['types']['fullSearchSchema'],\n RootSearchSchema\n >\n : Partial<Omit<FullSearchSchema<TRouteTree>, keyof RootSearchSchema>>,\n TSelected = TSearch,\n>(\n opts: StrictOrFrom<TFrom, TReturnIntersection> & {\n select?: (search: TSearch) => TSelected\n },\n): TSelected {\n return useMatch({\n ...opts,\n select: (match: MakeRouteMatch<TRouteTree, TFrom>) => {\n return opts.select ? opts.select(match.search) : match.search\n },\n })\n}\n"],"names":[],"mappings":";AAOO,SAAS,UAYd,MAGW;AACX,SAAO,SAAS;AAAA,IACd,GAAG;AAAA,IACH,QAAQ,CAAC,UAA6C;AACpD,aAAO,KAAK,SAAS,KAAK,OAAO,MAAM,MAAM,IAAI,MAAM;AAAA,IACzD;AAAA,EAAA,CACD;AACH;"}
|
package/package.json
CHANGED
package/src/Matches.tsx
CHANGED
|
@@ -9,8 +9,13 @@ import { CatchNotFound, DefaultGlobalNotFound, isNotFound } from './not-found'
|
|
|
9
9
|
import { isRedirect } from './redirects'
|
|
10
10
|
import { type AnyRouter, type RegisteredRouter } from './router'
|
|
11
11
|
import { Transitioner } from './Transitioner'
|
|
12
|
+
import {
|
|
13
|
+
type AnyRoute,
|
|
14
|
+
type ReactNode,
|
|
15
|
+
type StaticDataRouteOption,
|
|
16
|
+
} from './route'
|
|
17
|
+
import { rootRouteId } from './root'
|
|
12
18
|
import type { ResolveRelativePath, ToOptions } from './link'
|
|
13
|
-
import type { AnyRoute, ReactNode, StaticDataRouteOption } from './route'
|
|
14
19
|
import type {
|
|
15
20
|
AllParams,
|
|
16
21
|
FullSearchSchema,
|
|
@@ -20,13 +25,7 @@ import type {
|
|
|
20
25
|
RouteIds,
|
|
21
26
|
RoutePaths,
|
|
22
27
|
} from './routeInfo'
|
|
23
|
-
import type {
|
|
24
|
-
ControlledPromise,
|
|
25
|
-
DeepPartial,
|
|
26
|
-
Expand,
|
|
27
|
-
NoInfer,
|
|
28
|
-
StrictOrFrom,
|
|
29
|
-
} from './utils'
|
|
28
|
+
import type { ControlledPromise, DeepPartial, NoInfer } from './utils'
|
|
30
29
|
|
|
31
30
|
export const matchContext = React.createContext<string | undefined>(undefined)
|
|
32
31
|
|
|
@@ -417,7 +416,19 @@ export const Outlet = React.memo(function Outlet() {
|
|
|
417
416
|
return null
|
|
418
417
|
}
|
|
419
418
|
|
|
420
|
-
|
|
419
|
+
const nextMatch = <Match matchId={childMatchId} />
|
|
420
|
+
|
|
421
|
+
const pendingElement = router.options.defaultPendingComponent ? (
|
|
422
|
+
<router.options.defaultPendingComponent />
|
|
423
|
+
) : null
|
|
424
|
+
|
|
425
|
+
if (matchId === rootRouteId) {
|
|
426
|
+
return (
|
|
427
|
+
<React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>
|
|
428
|
+
)
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
return nextMatch
|
|
421
432
|
})
|
|
422
433
|
|
|
423
434
|
function renderRouteNotFound(router: AnyRouter, route: AnyRoute, data: any) {
|
|
@@ -532,39 +543,6 @@ export function MatchRoute<
|
|
|
532
543
|
return params ? props.children : null
|
|
533
544
|
}
|
|
534
545
|
|
|
535
|
-
export function useMatch<
|
|
536
|
-
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
537
|
-
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
538
|
-
TReturnIntersection extends boolean = false,
|
|
539
|
-
TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TReturnIntersection>,
|
|
540
|
-
TSelected = TRouteMatch,
|
|
541
|
-
>(
|
|
542
|
-
opts: StrictOrFrom<TFrom, TReturnIntersection> & {
|
|
543
|
-
select?: (match: TRouteMatch) => TSelected
|
|
544
|
-
},
|
|
545
|
-
): TSelected {
|
|
546
|
-
const nearestMatchId = React.useContext(matchContext)
|
|
547
|
-
|
|
548
|
-
const matchSelection = useRouterState({
|
|
549
|
-
select: (state) => {
|
|
550
|
-
const match = state.matches.find((d) =>
|
|
551
|
-
opts.from ? opts.from === d.routeId : d.id === nearestMatchId,
|
|
552
|
-
)
|
|
553
|
-
|
|
554
|
-
invariant(
|
|
555
|
-
match,
|
|
556
|
-
`Could not find ${
|
|
557
|
-
opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'
|
|
558
|
-
}`,
|
|
559
|
-
)
|
|
560
|
-
|
|
561
|
-
return opts.select ? opts.select(match as any) : match
|
|
562
|
-
},
|
|
563
|
-
})
|
|
564
|
-
|
|
565
|
-
return matchSelection as TSelected
|
|
566
|
-
}
|
|
567
|
-
|
|
568
546
|
export function useMatches<
|
|
569
547
|
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
570
548
|
TRouteId extends RouteIds<TRouteTree> = ParseRoute<TRouteTree>['id'],
|
|
@@ -634,52 +612,6 @@ export function useChildMatches<
|
|
|
634
612
|
})
|
|
635
613
|
}
|
|
636
614
|
|
|
637
|
-
export function useLoaderDeps<
|
|
638
|
-
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
639
|
-
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
640
|
-
TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<
|
|
641
|
-
TRouteTree,
|
|
642
|
-
TFrom
|
|
643
|
-
>,
|
|
644
|
-
TSelected = Required<TRouteMatch>['loaderDeps'],
|
|
645
|
-
>(
|
|
646
|
-
opts: StrictOrFrom<TFrom> & {
|
|
647
|
-
select?: (match: TRouteMatch) => TSelected
|
|
648
|
-
},
|
|
649
|
-
): TSelected {
|
|
650
|
-
return useMatch({
|
|
651
|
-
...opts,
|
|
652
|
-
select: (s) => {
|
|
653
|
-
return typeof opts.select === 'function'
|
|
654
|
-
? opts.select(s.loaderDeps)
|
|
655
|
-
: s.loaderDeps
|
|
656
|
-
},
|
|
657
|
-
})
|
|
658
|
-
}
|
|
659
|
-
|
|
660
|
-
export function useLoaderData<
|
|
661
|
-
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
662
|
-
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
663
|
-
TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<
|
|
664
|
-
TRouteTree,
|
|
665
|
-
TFrom
|
|
666
|
-
>,
|
|
667
|
-
TSelected = Required<TRouteMatch>['loaderData'],
|
|
668
|
-
>(
|
|
669
|
-
opts: StrictOrFrom<TFrom> & {
|
|
670
|
-
select?: (match: TRouteMatch) => TSelected
|
|
671
|
-
},
|
|
672
|
-
): TSelected {
|
|
673
|
-
return useMatch({
|
|
674
|
-
...opts,
|
|
675
|
-
select: (s) => {
|
|
676
|
-
return typeof opts.select === 'function'
|
|
677
|
-
? opts.select(s.loaderData as TRouteMatch)
|
|
678
|
-
: s.loaderData
|
|
679
|
-
},
|
|
680
|
-
}) as TSelected
|
|
681
|
-
}
|
|
682
|
-
|
|
683
615
|
export function isServerSideError(error: unknown): error is {
|
|
684
616
|
__isServerError: true
|
|
685
617
|
data: Record<string, any>
|
package/src/fileRoute.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import warning from 'tiny-warning'
|
|
2
2
|
import { createRoute } from './route'
|
|
3
|
-
import {
|
|
3
|
+
import { useMatch } from './useMatch'
|
|
4
|
+
import { useLoaderDeps } from './useLoaderDeps'
|
|
5
|
+
import { useLoaderData } from './useLoaderData'
|
|
4
6
|
import { useSearch } from './useSearch'
|
|
5
7
|
import { useParams } from './useParams'
|
|
6
8
|
import { useNavigate } from './useNavigate'
|
|
@@ -18,7 +20,6 @@ import type {
|
|
|
18
20
|
ResolveLoaderData,
|
|
19
21
|
ResolveRouteContext,
|
|
20
22
|
ResolveSearchSchemaUsed,
|
|
21
|
-
RootRouteId,
|
|
22
23
|
Route,
|
|
23
24
|
RouteConstraints,
|
|
24
25
|
RouteContext,
|
|
@@ -32,6 +33,7 @@ import type { MakeRouteMatch } from './Matches'
|
|
|
32
33
|
import type { NoInfer } from '@tanstack/react-store'
|
|
33
34
|
import type { RegisteredRouter } from './router'
|
|
34
35
|
import type { RouteById, RouteIds } from './routeInfo'
|
|
36
|
+
import type { RootRouteId } from './root'
|
|
35
37
|
|
|
36
38
|
export interface FileRoutesByPath {
|
|
37
39
|
// '/': {
|
package/src/index.tsx
CHANGED
|
@@ -74,12 +74,9 @@ export {
|
|
|
74
74
|
Outlet,
|
|
75
75
|
useMatchRoute,
|
|
76
76
|
MatchRoute,
|
|
77
|
-
useMatch,
|
|
78
77
|
useMatches,
|
|
79
78
|
useParentMatches,
|
|
80
79
|
useChildMatches,
|
|
81
|
-
useLoaderDeps,
|
|
82
|
-
useLoaderData,
|
|
83
80
|
isServerSideError,
|
|
84
81
|
defaultDeserializeError,
|
|
85
82
|
type RouteMatch,
|
|
@@ -88,6 +85,9 @@ export {
|
|
|
88
85
|
type UseMatchRouteOptions,
|
|
89
86
|
type MakeMatchRouteOptions,
|
|
90
87
|
} from './Matches'
|
|
88
|
+
export { useMatch } from './useMatch'
|
|
89
|
+
export { useLoaderDeps } from './useLoaderDeps'
|
|
90
|
+
export { useLoaderData } from './useLoaderData'
|
|
91
91
|
export {
|
|
92
92
|
joinPaths,
|
|
93
93
|
cleanPath,
|
|
@@ -110,8 +110,8 @@ export {
|
|
|
110
110
|
type Redirect,
|
|
111
111
|
type ResolvedRedirect,
|
|
112
112
|
} from './redirects'
|
|
113
|
+
export { rootRouteId, type RootRouteId } from './root'
|
|
113
114
|
export {
|
|
114
|
-
rootRouteId,
|
|
115
115
|
RouteApi,
|
|
116
116
|
getRouteApi,
|
|
117
117
|
Route,
|
|
@@ -122,7 +122,6 @@ export {
|
|
|
122
122
|
createRootRouteWithContext,
|
|
123
123
|
createRouteMask,
|
|
124
124
|
NotFoundRoute,
|
|
125
|
-
type RootRouteId,
|
|
126
125
|
type AnyPathParams,
|
|
127
126
|
type SearchSchemaInput,
|
|
128
127
|
type AnySearchSchema,
|
package/src/link.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react'
|
|
2
2
|
import { flushSync } from 'react-dom'
|
|
3
|
-
import { useMatch } from './
|
|
3
|
+
import { useMatch } from './useMatch'
|
|
4
4
|
import { useRouterState } from './useRouterState'
|
|
5
5
|
import { useRouter } from './useRouter'
|
|
6
6
|
import { deepEqual, exactPathTest, functionalUpdate } from './utils'
|
package/src/root.ts
ADDED
package/src/route.ts
CHANGED
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
import invariant from 'tiny-invariant'
|
|
2
|
-
import {
|
|
2
|
+
import { useMatch } from './useMatch'
|
|
3
|
+
import { useLoaderDeps } from './useLoaderDeps'
|
|
4
|
+
import { useLoaderData } from './useLoaderData'
|
|
3
5
|
import { joinPaths, trimPathLeft } from './path'
|
|
4
6
|
import { useParams } from './useParams'
|
|
5
7
|
import { useSearch } from './useSearch'
|
|
6
8
|
import { notFound } from './not-found'
|
|
7
9
|
import { useNavigate } from './useNavigate'
|
|
10
|
+
import { rootRouteId } from './root'
|
|
11
|
+
import type { RootRouteId } from './root'
|
|
8
12
|
import type { UseNavigateResult } from './useNavigate'
|
|
9
13
|
import type * as React from 'react'
|
|
10
14
|
import type { MakeRouteMatch, RouteMatch } from './Matches'
|
|
@@ -24,8 +28,6 @@ import type { BuildLocationFn, NavigateFn } from './RouterProvider'
|
|
|
24
28
|
import type { NotFoundError } from './not-found'
|
|
25
29
|
import type { LazyRoute } from './fileRoute'
|
|
26
30
|
|
|
27
|
-
export const rootRouteId = '__root__' as const
|
|
28
|
-
export type RootRouteId = typeof rootRouteId
|
|
29
31
|
export type AnyPathParams = {}
|
|
30
32
|
|
|
31
33
|
export type SearchSchemaInput = {
|
package/src/router.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { createBrowserHistory, createMemoryHistory } from '@tanstack/history'
|
|
|
2
2
|
import { Store } from '@tanstack/react-store'
|
|
3
3
|
import invariant from 'tiny-invariant'
|
|
4
4
|
import warning from 'tiny-warning'
|
|
5
|
-
import { rootRouteId } from './
|
|
5
|
+
import { rootRouteId } from './root'
|
|
6
6
|
import { defaultParseSearch, defaultStringifySearch } from './searchParams'
|
|
7
7
|
import {
|
|
8
8
|
createControlledPromise,
|
|
@@ -1453,13 +1453,12 @@ export class Router<
|
|
|
1453
1453
|
}))
|
|
1454
1454
|
// }
|
|
1455
1455
|
|
|
1456
|
-
rendered = true
|
|
1457
|
-
|
|
1458
1456
|
if (!(err as any).routeId) {
|
|
1459
1457
|
;(err as any).routeId = match.routeId
|
|
1460
1458
|
}
|
|
1461
1459
|
|
|
1462
1460
|
if (isRedirect(err)) {
|
|
1461
|
+
rendered = true
|
|
1463
1462
|
err = this.resolveRedirect(err)
|
|
1464
1463
|
throw err
|
|
1465
1464
|
} else if (isNotFound(err)) {
|
|
@@ -1862,6 +1861,10 @@ export class Router<
|
|
|
1862
1861
|
await triggerOnReady()
|
|
1863
1862
|
} catch (err) {
|
|
1864
1863
|
if (isRedirect(err) || isNotFound(err)) {
|
|
1864
|
+
if (isNotFound(err) && !preload) {
|
|
1865
|
+
console.log('trigger')
|
|
1866
|
+
await triggerOnReady()
|
|
1867
|
+
}
|
|
1865
1868
|
throw err
|
|
1866
1869
|
}
|
|
1867
1870
|
}
|
|
@@ -2151,7 +2154,7 @@ export class Router<
|
|
|
2151
2154
|
|
|
2152
2155
|
invariant(
|
|
2153
2156
|
_ctx,
|
|
2154
|
-
'Expected to find a __TSR_DEHYDRATED__ property on window... but we did not.
|
|
2157
|
+
'Expected to find a __TSR_DEHYDRATED__ property on window... but we did not. Please file an issue!',
|
|
2155
2158
|
)
|
|
2156
2159
|
|
|
2157
2160
|
const ctx = this.options.transformer.parse(_ctx) as HydrationCtx
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RegisteredRouter } from './router'
|
|
2
|
+
import { type AnyRoute } from './route'
|
|
3
|
+
import { useMatch } from './useMatch'
|
|
4
|
+
import type { MakeRouteMatch } from './Matches'
|
|
5
|
+
import type { RouteIds } from './routeInfo'
|
|
6
|
+
import type { StrictOrFrom } from './utils'
|
|
7
|
+
|
|
8
|
+
export function useLoaderData<
|
|
9
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
10
|
+
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
11
|
+
TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<
|
|
12
|
+
TRouteTree,
|
|
13
|
+
TFrom
|
|
14
|
+
>,
|
|
15
|
+
TSelected = Required<TRouteMatch>['loaderData'],
|
|
16
|
+
>(
|
|
17
|
+
opts: StrictOrFrom<TFrom> & {
|
|
18
|
+
select?: (match: TRouteMatch) => TSelected
|
|
19
|
+
},
|
|
20
|
+
): TSelected {
|
|
21
|
+
return useMatch({
|
|
22
|
+
...opts,
|
|
23
|
+
select: (s) => {
|
|
24
|
+
return typeof opts.select === 'function'
|
|
25
|
+
? opts.select(s.loaderData as TRouteMatch)
|
|
26
|
+
: s.loaderData
|
|
27
|
+
},
|
|
28
|
+
}) as TSelected
|
|
29
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type RegisteredRouter } from './router'
|
|
2
|
+
import { type AnyRoute } from './route'
|
|
3
|
+
import { useMatch } from './useMatch'
|
|
4
|
+
import type { MakeRouteMatch } from './Matches'
|
|
5
|
+
import type { RouteIds } from './routeInfo'
|
|
6
|
+
import type { StrictOrFrom } from './utils'
|
|
7
|
+
|
|
8
|
+
export function useLoaderDeps<
|
|
9
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
10
|
+
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
11
|
+
TRouteMatch extends MakeRouteMatch<TRouteTree, TFrom> = MakeRouteMatch<
|
|
12
|
+
TRouteTree,
|
|
13
|
+
TFrom
|
|
14
|
+
>,
|
|
15
|
+
TSelected = Required<TRouteMatch>['loaderDeps'],
|
|
16
|
+
>(
|
|
17
|
+
opts: StrictOrFrom<TFrom> & {
|
|
18
|
+
select?: (match: TRouteMatch) => TSelected
|
|
19
|
+
},
|
|
20
|
+
): TSelected {
|
|
21
|
+
return useMatch({
|
|
22
|
+
...opts,
|
|
23
|
+
select: (s) => {
|
|
24
|
+
return typeof opts.select === 'function'
|
|
25
|
+
? opts.select(s.loaderDeps)
|
|
26
|
+
: s.loaderDeps
|
|
27
|
+
},
|
|
28
|
+
})
|
|
29
|
+
}
|
package/src/useMatch.tsx
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import * as React from 'react'
|
|
2
|
+
import invariant from 'tiny-invariant'
|
|
3
|
+
import { useRouterState } from './useRouterState'
|
|
4
|
+
import { type RegisteredRouter } from './router'
|
|
5
|
+
import { type AnyRoute } from './route'
|
|
6
|
+
import { matchContext } from './Matches'
|
|
7
|
+
import type { MakeRouteMatch } from './Matches'
|
|
8
|
+
import type { RouteIds } from './routeInfo'
|
|
9
|
+
import type { StrictOrFrom } from './utils'
|
|
10
|
+
|
|
11
|
+
export function useMatch<
|
|
12
|
+
TRouteTree extends AnyRoute = RegisteredRouter['routeTree'],
|
|
13
|
+
TFrom extends RouteIds<TRouteTree> = RouteIds<TRouteTree>,
|
|
14
|
+
TReturnIntersection extends boolean = false,
|
|
15
|
+
TRouteMatch = MakeRouteMatch<TRouteTree, TFrom, TReturnIntersection>,
|
|
16
|
+
TSelected = TRouteMatch,
|
|
17
|
+
>(
|
|
18
|
+
opts: StrictOrFrom<TFrom, TReturnIntersection> & {
|
|
19
|
+
select?: (match: TRouteMatch) => TSelected
|
|
20
|
+
},
|
|
21
|
+
): TSelected {
|
|
22
|
+
const nearestMatchId = React.useContext(matchContext)
|
|
23
|
+
|
|
24
|
+
const matchSelection = useRouterState({
|
|
25
|
+
select: (state) => {
|
|
26
|
+
const match = state.matches.find((d) =>
|
|
27
|
+
opts.from ? opts.from === d.routeId : d.id === nearestMatchId,
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
invariant(
|
|
31
|
+
match,
|
|
32
|
+
`Could not find ${opts.from ? `an active match from "${opts.from}"` : 'a nearest match!'}`,
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
return opts.select ? opts.select(match as any) : match
|
|
36
|
+
},
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
return matchSelection as TSelected
|
|
40
|
+
}
|
package/src/useNavigate.tsx
CHANGED
package/src/useParams.tsx
CHANGED
package/src/useRouteContext.ts
CHANGED
package/src/useSearch.tsx
CHANGED