@tanstack/vue-router 0.0.1 → 1.140.1
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/LICENSE +21 -0
- package/README.md +66 -45
- package/dist/esm/Asset.d.ts +2 -0
- package/dist/esm/Asset.js +33 -0
- package/dist/esm/Asset.js.map +1 -0
- package/dist/esm/CatchBoundary.d.ts +19 -0
- package/dist/esm/CatchBoundary.js +135 -0
- package/dist/esm/CatchBoundary.js.map +1 -0
- package/dist/esm/ClientOnly.d.ts +67 -0
- package/dist/esm/HeadContent.d.ts +10 -0
- package/dist/esm/HeadContent.js +116 -0
- package/dist/esm/HeadContent.js.map +1 -0
- package/dist/esm/Match.d.ts +25 -0
- package/dist/esm/Match.js +262 -0
- package/dist/esm/Match.js.map +1 -0
- package/dist/esm/Matches.d.ts +39 -0
- package/dist/esm/Matches.js +186 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +33 -0
- package/dist/esm/RouterProvider.js +65 -0
- package/dist/esm/RouterProvider.js.map +1 -0
- package/dist/esm/SafeFragment.d.ts +4 -0
- package/dist/esm/ScriptOnce.d.ts +5 -0
- package/dist/esm/ScriptOnce.js +21 -0
- package/dist/esm/ScriptOnce.js.map +1 -0
- package/dist/esm/Scripts.d.ts +1 -0
- package/dist/esm/Scripts.js +46 -0
- package/dist/esm/Scripts.js.map +1 -0
- package/dist/esm/ScrollRestoration.d.ts +14 -0
- package/dist/esm/ScrollRestoration.js +36 -0
- package/dist/esm/ScrollRestoration.js.map +1 -0
- package/dist/esm/Transitioner.d.ts +2 -0
- package/dist/esm/Transitioner.js +154 -0
- package/dist/esm/Transitioner.js.map +1 -0
- package/dist/esm/awaited.d.ts +12 -0
- package/dist/esm/awaited.js +40 -0
- package/dist/esm/awaited.js.map +1 -0
- package/dist/esm/fileRoute.d.ts +54 -0
- package/dist/esm/fileRoute.js +103 -0
- package/dist/esm/fileRoute.js.map +1 -0
- package/dist/esm/history.d.ts +8 -0
- package/dist/esm/index.d.ts +51 -0
- package/dist/esm/index.js +138 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lazyRouteComponent.d.ts +8 -0
- package/dist/esm/lazyRouteComponent.js +106 -0
- package/dist/esm/lazyRouteComponent.js.map +1 -0
- package/dist/esm/link.d.ts +61 -0
- package/dist/esm/link.js +376 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/matchContext.d.ts +20 -0
- package/dist/esm/matchContext.js +16 -0
- package/dist/esm/matchContext.js.map +1 -0
- package/dist/esm/not-found.d.ts +12 -0
- package/dist/esm/not-found.js +45 -0
- package/dist/esm/not-found.js.map +1 -0
- package/dist/esm/renderRouteNotFound.d.ts +11 -0
- package/dist/esm/renderRouteNotFound.js +19 -0
- package/dist/esm/renderRouteNotFound.js.map +1 -0
- package/dist/esm/route.d.ts +96 -0
- package/dist/esm/route.js +176 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/router.d.ts +69 -0
- package/dist/esm/router.js +14 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/routerContext.d.ts +21 -0
- package/dist/esm/routerContext.js +21 -0
- package/dist/esm/routerContext.js.map +1 -0
- package/dist/esm/scroll-restoration.d.ts +1 -0
- package/dist/esm/scroll-restoration.js +21 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/typePrimitives.d.ts +10 -0
- package/dist/esm/useBlocker.d.ts +66 -0
- package/dist/esm/useBlocker.js +295 -0
- package/dist/esm/useBlocker.js.map +1 -0
- package/dist/esm/useCanGoBack.d.ts +1 -0
- package/dist/esm/useCanGoBack.js +8 -0
- package/dist/esm/useCanGoBack.js.map +1 -0
- package/dist/esm/useLoaderData.d.ts +8 -0
- package/dist/esm/useLoaderData.js +14 -0
- package/dist/esm/useLoaderData.js.map +1 -0
- package/dist/esm/useLoaderDeps.d.ts +7 -0
- package/dist/esm/useLoaderDeps.js +17 -0
- package/dist/esm/useLoaderDeps.js.map +1 -0
- package/dist/esm/useLocation.d.ts +7 -0
- package/dist/esm/useLocation.js +10 -0
- package/dist/esm/useLocation.js.map +1 -0
- package/dist/esm/useMatch.d.ts +10 -0
- package/dist/esm/useMatch.js +39 -0
- package/dist/esm/useMatch.js.map +1 -0
- package/dist/esm/useNavigate.d.ts +5 -0
- package/dist/esm/useNavigate.js +29 -0
- package/dist/esm/useNavigate.js.map +1 -0
- package/dist/esm/useParams.d.ts +9 -0
- package/dist/esm/useParams.js +15 -0
- package/dist/esm/useParams.js.map +1 -0
- package/dist/esm/useRouteContext.d.ts +4 -0
- package/dist/esm/useRouteContext.js +11 -0
- package/dist/esm/useRouteContext.js.map +1 -0
- package/dist/esm/useRouter.d.ts +4 -0
- package/dist/esm/useRouter.js +12 -0
- package/dist/esm/useRouter.js.map +1 -0
- package/dist/esm/useRouterState.d.ts +8 -0
- package/dist/esm/useRouterState.js +20 -0
- package/dist/esm/useRouterState.js.map +1 -0
- package/dist/esm/useSearch.d.ts +9 -0
- package/dist/esm/useSearch.js +15 -0
- package/dist/esm/useSearch.js.map +1 -0
- package/dist/esm/utils.d.ts +40 -0
- package/dist/esm/utils.js +44 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/source/Asset.d.ts +2 -0
- package/dist/source/Asset.jsx +22 -0
- package/dist/source/Asset.jsx.map +1 -0
- package/dist/source/CatchBoundary.d.ts +19 -0
- package/dist/source/CatchBoundary.jsx +134 -0
- package/dist/source/CatchBoundary.jsx.map +1 -0
- package/dist/source/ClientOnly.d.ts +67 -0
- package/dist/source/ClientOnly.jsx +63 -0
- package/dist/source/ClientOnly.jsx.map +1 -0
- package/dist/source/HeadContent.d.ts +10 -0
- package/dist/source/HeadContent.jsx +133 -0
- package/dist/source/HeadContent.jsx.map +1 -0
- package/dist/source/Match.d.ts +25 -0
- package/dist/source/Match.jsx +316 -0
- package/dist/source/Match.jsx.map +1 -0
- package/dist/source/Matches.d.ts +39 -0
- package/dist/source/Matches.jsx +191 -0
- package/dist/source/Matches.jsx.map +1 -0
- package/dist/source/RouterProvider.d.ts +33 -0
- package/dist/source/RouterProvider.jsx +63 -0
- package/dist/source/RouterProvider.jsx.map +1 -0
- package/dist/source/SafeFragment.d.ts +4 -0
- package/dist/source/SafeFragment.jsx +10 -0
- package/dist/source/SafeFragment.jsx.map +1 -0
- package/dist/source/ScriptOnce.d.ts +5 -0
- package/dist/source/ScriptOnce.jsx +17 -0
- package/dist/source/ScriptOnce.jsx.map +1 -0
- package/dist/source/Scripts.d.ts +1 -0
- package/dist/source/Scripts.jsx +49 -0
- package/dist/source/Scripts.jsx.map +1 -0
- package/dist/source/ScrollRestoration.d.ts +14 -0
- package/dist/source/ScrollRestoration.jsx +37 -0
- package/dist/source/ScrollRestoration.jsx.map +1 -0
- package/dist/source/Transitioner.d.ts +2 -0
- package/dist/source/Transitioner.jsx +181 -0
- package/dist/source/Transitioner.jsx.map +1 -0
- package/dist/source/awaited.d.ts +12 -0
- package/dist/source/awaited.jsx +38 -0
- package/dist/source/awaited.jsx.map +1 -0
- package/dist/source/fileRoute.d.ts +54 -0
- package/dist/source/fileRoute.js +98 -0
- package/dist/source/fileRoute.js.map +1 -0
- package/dist/source/history.d.ts +8 -0
- package/dist/source/history.js +2 -0
- package/dist/source/history.js.map +1 -0
- package/dist/source/index.d.ts +51 -0
- package/dist/source/index.jsx +40 -0
- package/dist/source/index.jsx.map +1 -0
- package/dist/source/lazyRouteComponent.d.ts +8 -0
- package/dist/source/lazyRouteComponent.jsx +135 -0
- package/dist/source/lazyRouteComponent.jsx.map +1 -0
- package/dist/source/link.d.ts +61 -0
- package/dist/source/link.jsx +495 -0
- package/dist/source/link.jsx.map +1 -0
- package/dist/source/matchContext.d.ts +20 -0
- package/dist/source/matchContext.jsx +32 -0
- package/dist/source/matchContext.jsx.map +1 -0
- package/dist/source/not-found.d.ts +12 -0
- package/dist/source/not-found.jsx +48 -0
- package/dist/source/not-found.jsx.map +1 -0
- package/dist/source/renderRouteNotFound.d.ts +11 -0
- package/dist/source/renderRouteNotFound.jsx +24 -0
- package/dist/source/renderRouteNotFound.jsx.map +1 -0
- package/dist/source/route.d.ts +97 -0
- package/dist/source/route.js +167 -0
- package/dist/source/route.js.map +1 -0
- package/dist/source/router.d.ts +70 -0
- package/dist/source/router.js +10 -0
- package/dist/source/router.js.map +1 -0
- package/dist/source/routerContext.d.ts +21 -0
- package/dist/source/routerContext.jsx +37 -0
- package/dist/source/routerContext.jsx.map +1 -0
- package/dist/source/scroll-restoration.d.ts +1 -0
- package/dist/source/scroll-restoration.jsx +16 -0
- package/dist/source/scroll-restoration.jsx.map +1 -0
- package/dist/source/typePrimitives.d.ts +10 -0
- package/dist/source/typePrimitives.js +2 -0
- package/dist/source/typePrimitives.js.map +1 -0
- package/dist/source/useBlocker.d.ts +66 -0
- package/dist/source/useBlocker.jsx +308 -0
- package/dist/source/useBlocker.jsx.map +1 -0
- package/dist/source/useCanGoBack.d.ts +1 -0
- package/dist/source/useCanGoBack.js +5 -0
- package/dist/source/useCanGoBack.js.map +1 -0
- package/dist/source/useLoaderData.d.ts +8 -0
- package/dist/source/useLoaderData.jsx +11 -0
- package/dist/source/useLoaderData.jsx.map +1 -0
- package/dist/source/useLoaderDeps.d.ts +7 -0
- package/dist/source/useLoaderDeps.jsx +11 -0
- package/dist/source/useLoaderDeps.jsx.map +1 -0
- package/dist/source/useLocation.d.ts +7 -0
- package/dist/source/useLocation.jsx +7 -0
- package/dist/source/useLocation.jsx.map +1 -0
- package/dist/source/useMatch.d.ts +10 -0
- package/dist/source/useMatch.jsx +46 -0
- package/dist/source/useMatch.jsx.map +1 -0
- package/dist/source/useNavigate.d.ts +5 -0
- package/dist/source/useNavigate.jsx +18 -0
- package/dist/source/useNavigate.jsx.map +1 -0
- package/dist/source/useParams.d.ts +9 -0
- package/dist/source/useParams.jsx +12 -0
- package/dist/source/useParams.jsx.map +1 -0
- package/dist/source/useRouteContext.d.ts +4 -0
- package/dist/source/useRouteContext.js +8 -0
- package/dist/source/useRouteContext.js.map +1 -0
- package/dist/source/useRouter.d.ts +4 -0
- package/dist/source/useRouter.jsx +9 -0
- package/dist/source/useRouter.jsx.map +1 -0
- package/dist/source/useRouterState.d.ts +8 -0
- package/dist/source/useRouterState.jsx +19 -0
- package/dist/source/useRouterState.jsx.map +1 -0
- package/dist/source/useSearch.d.ts +9 -0
- package/dist/source/useSearch.jsx +12 -0
- package/dist/source/useSearch.jsx.map +1 -0
- package/dist/source/utils.d.ts +40 -0
- package/dist/source/utils.js +78 -0
- package/dist/source/utils.js.map +1 -0
- package/package.json +77 -7
- package/src/Asset.tsx +23 -0
- package/src/CatchBoundary.tsx +186 -0
- package/src/ClientOnly.tsx +75 -0
- package/src/HeadContent.tsx +159 -0
- package/src/Match.tsx +415 -0
- package/src/Matches.tsx +349 -0
- package/src/RouterProvider.tsx +117 -0
- package/src/SafeFragment.tsx +10 -0
- package/src/ScriptOnce.tsx +30 -0
- package/src/Scripts.tsx +65 -0
- package/src/ScrollRestoration.tsx +69 -0
- package/src/Transitioner.tsx +213 -0
- package/src/awaited.tsx +54 -0
- package/src/fileRoute.ts +271 -0
- package/src/history.ts +9 -0
- package/src/index.tsx +346 -0
- package/src/lazyRouteComponent.tsx +173 -0
- package/src/link.tsx +765 -0
- package/src/matchContext.tsx +41 -0
- package/src/not-found.tsx +55 -0
- package/src/renderRouteNotFound.tsx +35 -0
- package/src/route.ts +658 -0
- package/src/router.ts +103 -0
- package/src/routerContext.tsx +53 -0
- package/src/scroll-restoration.tsx +29 -0
- package/src/typePrimitives.ts +74 -0
- package/src/useBlocker.tsx +501 -0
- package/src/useCanGoBack.ts +5 -0
- package/src/useLoaderData.tsx +50 -0
- package/src/useLoaderDeps.tsx +46 -0
- package/src/useLocation.tsx +30 -0
- package/src/useMatch.tsx +127 -0
- package/src/useNavigate.tsx +40 -0
- package/src/useParams.tsx +71 -0
- package/src/useRouteContext.ts +31 -0
- package/src/useRouter.tsx +15 -0
- package/src/useRouterState.tsx +43 -0
- package/src/useSearch.tsx +71 -0
- package/src/utils.ts +111 -0
package/src/route.ts
ADDED
|
@@ -0,0 +1,658 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseRootRoute,
|
|
3
|
+
BaseRoute,
|
|
4
|
+
BaseRouteApi,
|
|
5
|
+
notFound,
|
|
6
|
+
} from '@tanstack/router-core'
|
|
7
|
+
import { useLoaderData } from './useLoaderData'
|
|
8
|
+
import { useLoaderDeps } from './useLoaderDeps'
|
|
9
|
+
import { useParams } from './useParams'
|
|
10
|
+
import { useSearch } from './useSearch'
|
|
11
|
+
import { useNavigate } from './useNavigate'
|
|
12
|
+
import { useMatch } from './useMatch'
|
|
13
|
+
import { useRouter } from './useRouter'
|
|
14
|
+
import type {
|
|
15
|
+
AnyContext,
|
|
16
|
+
AnyRoute,
|
|
17
|
+
AnyRouter,
|
|
18
|
+
ConstrainLiteral,
|
|
19
|
+
ErrorComponentProps,
|
|
20
|
+
NotFoundError,
|
|
21
|
+
NotFoundRouteProps,
|
|
22
|
+
Register,
|
|
23
|
+
RegisteredRouter,
|
|
24
|
+
ResolveFullPath,
|
|
25
|
+
ResolveId,
|
|
26
|
+
ResolveParams,
|
|
27
|
+
RootRoute as RootRouteCore,
|
|
28
|
+
RootRouteId,
|
|
29
|
+
RootRouteOptions,
|
|
30
|
+
RouteConstraints,
|
|
31
|
+
Route as RouteCore,
|
|
32
|
+
RouteIds,
|
|
33
|
+
RouteMask,
|
|
34
|
+
RouteOptions,
|
|
35
|
+
RouteTypesById,
|
|
36
|
+
RouterCore,
|
|
37
|
+
ToMaskOptions,
|
|
38
|
+
UseNavigateResult,
|
|
39
|
+
} from '@tanstack/router-core'
|
|
40
|
+
import type { UseLoaderDataRoute } from './useLoaderData'
|
|
41
|
+
import type { UseMatchRoute } from './useMatch'
|
|
42
|
+
import type { UseLoaderDepsRoute } from './useLoaderDeps'
|
|
43
|
+
import type { UseParamsRoute } from './useParams'
|
|
44
|
+
import type { UseSearchRoute } from './useSearch'
|
|
45
|
+
import type * as Vue from 'vue'
|
|
46
|
+
import type { UseRouteContextRoute } from './useRouteContext'
|
|
47
|
+
|
|
48
|
+
// Structural type for Vue SFC components (.vue files)
|
|
49
|
+
// Uses structural matching to accept Vue components without breaking
|
|
50
|
+
// TypeScript inference for inline function components
|
|
51
|
+
type VueSFC = {
|
|
52
|
+
readonly __name?: string
|
|
53
|
+
setup?: (...args: Array<any>) => any
|
|
54
|
+
render?: Function
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
declare module '@tanstack/router-core' {
|
|
58
|
+
export interface UpdatableRouteOptionsExtensions {
|
|
59
|
+
component?: RouteComponent | VueSFC
|
|
60
|
+
errorComponent?: false | null | undefined | ErrorRouteComponent | VueSFC
|
|
61
|
+
notFoundComponent?: NotFoundRouteComponent | VueSFC
|
|
62
|
+
pendingComponent?: RouteComponent | VueSFC
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export interface RouteExtensions<
|
|
66
|
+
in out TId extends string,
|
|
67
|
+
in out TFullPath extends string,
|
|
68
|
+
> {
|
|
69
|
+
useMatch: UseMatchRoute<TId>
|
|
70
|
+
useRouteContext: UseRouteContextRoute<TId>
|
|
71
|
+
useSearch: UseSearchRoute<TId>
|
|
72
|
+
useParams: UseParamsRoute<TId>
|
|
73
|
+
useLoaderDeps: UseLoaderDepsRoute<TId>
|
|
74
|
+
useLoaderData: UseLoaderDataRoute<TId>
|
|
75
|
+
useNavigate: () => UseNavigateResult<TFullPath>
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export function getRouteApi<
|
|
80
|
+
const TId,
|
|
81
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
82
|
+
>(id: ConstrainLiteral<TId, RouteIds<TRouter['routeTree']>>) {
|
|
83
|
+
return new RouteApi<TId, TRouter>({ id })
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export class RouteApi<
|
|
87
|
+
TId,
|
|
88
|
+
TRouter extends AnyRouter = RegisteredRouter,
|
|
89
|
+
> extends BaseRouteApi<TId, TRouter> {
|
|
90
|
+
/**
|
|
91
|
+
* @deprecated Use the `getRouteApi` function instead.
|
|
92
|
+
*/
|
|
93
|
+
constructor({ id }: { id: TId }) {
|
|
94
|
+
super({ id })
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
useMatch: UseMatchRoute<TId> = (opts) => {
|
|
98
|
+
return useMatch({
|
|
99
|
+
select: opts?.select,
|
|
100
|
+
from: this.id,
|
|
101
|
+
} as any) as any
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
useRouteContext: UseRouteContextRoute<TId> = (opts) => {
|
|
105
|
+
return useMatch({
|
|
106
|
+
from: this.id as any,
|
|
107
|
+
select: (d) => (opts?.select ? opts.select(d.context) : d.context),
|
|
108
|
+
}) as any
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
useSearch: UseSearchRoute<TId> = (opts) => {
|
|
112
|
+
return useSearch({
|
|
113
|
+
select: opts?.select,
|
|
114
|
+
from: this.id,
|
|
115
|
+
} as any) as any
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
useParams: UseParamsRoute<TId> = (opts) => {
|
|
119
|
+
return useParams({
|
|
120
|
+
select: opts?.select,
|
|
121
|
+
from: this.id,
|
|
122
|
+
} as any) as any
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {
|
|
126
|
+
return useLoaderDeps({ ...opts, from: this.id, strict: false } as any)
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
useLoaderData: UseLoaderDataRoute<TId> = (opts) => {
|
|
130
|
+
return useLoaderData({ ...opts, from: this.id, strict: false } as any)
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
useNavigate = (): UseNavigateResult<
|
|
134
|
+
RouteTypesById<TRouter, TId>['fullPath']
|
|
135
|
+
> => {
|
|
136
|
+
const router = useRouter()
|
|
137
|
+
return useNavigate({ from: router.routesById[this.id as string].fullPath })
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
notFound = (opts?: NotFoundError) => {
|
|
141
|
+
return notFound({ routeId: this.id as string, ...opts })
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export class Route<
|
|
146
|
+
in out TRegister = unknown,
|
|
147
|
+
in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
148
|
+
in out TPath extends RouteConstraints['TPath'] = '/',
|
|
149
|
+
in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
150
|
+
TParentRoute,
|
|
151
|
+
TPath
|
|
152
|
+
>,
|
|
153
|
+
in out TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
154
|
+
in out TId extends RouteConstraints['TId'] = ResolveId<
|
|
155
|
+
TParentRoute,
|
|
156
|
+
TCustomId,
|
|
157
|
+
TPath
|
|
158
|
+
>,
|
|
159
|
+
in out TSearchValidator = undefined,
|
|
160
|
+
in out TParams = ResolveParams<TPath>,
|
|
161
|
+
in out TRouterContext = AnyContext,
|
|
162
|
+
in out TRouteContextFn = AnyContext,
|
|
163
|
+
in out TBeforeLoadFn = AnyContext,
|
|
164
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
165
|
+
in out TLoaderFn = undefined,
|
|
166
|
+
in out TChildren = unknown,
|
|
167
|
+
in out TFileRouteTypes = unknown,
|
|
168
|
+
in out TSSR = unknown,
|
|
169
|
+
in out TMiddlewares = unknown,
|
|
170
|
+
in out THandlers = undefined,
|
|
171
|
+
>
|
|
172
|
+
extends BaseRoute<
|
|
173
|
+
TRegister,
|
|
174
|
+
TParentRoute,
|
|
175
|
+
TPath,
|
|
176
|
+
TFullPath,
|
|
177
|
+
TCustomId,
|
|
178
|
+
TId,
|
|
179
|
+
TSearchValidator,
|
|
180
|
+
TParams,
|
|
181
|
+
TRouterContext,
|
|
182
|
+
TRouteContextFn,
|
|
183
|
+
TBeforeLoadFn,
|
|
184
|
+
TLoaderDeps,
|
|
185
|
+
TLoaderFn,
|
|
186
|
+
TChildren,
|
|
187
|
+
TFileRouteTypes,
|
|
188
|
+
TSSR,
|
|
189
|
+
TMiddlewares,
|
|
190
|
+
THandlers
|
|
191
|
+
>
|
|
192
|
+
implements
|
|
193
|
+
RouteCore<
|
|
194
|
+
TRegister,
|
|
195
|
+
TParentRoute,
|
|
196
|
+
TPath,
|
|
197
|
+
TFullPath,
|
|
198
|
+
TCustomId,
|
|
199
|
+
TId,
|
|
200
|
+
TSearchValidator,
|
|
201
|
+
TParams,
|
|
202
|
+
TRouterContext,
|
|
203
|
+
TRouteContextFn,
|
|
204
|
+
TBeforeLoadFn,
|
|
205
|
+
TLoaderDeps,
|
|
206
|
+
TLoaderFn,
|
|
207
|
+
TChildren,
|
|
208
|
+
TFileRouteTypes,
|
|
209
|
+
TSSR,
|
|
210
|
+
TMiddlewares,
|
|
211
|
+
THandlers
|
|
212
|
+
>
|
|
213
|
+
{
|
|
214
|
+
/**
|
|
215
|
+
* @deprecated Use the `createRoute` function instead.
|
|
216
|
+
*/
|
|
217
|
+
constructor(
|
|
218
|
+
options?: RouteOptions<
|
|
219
|
+
TRegister,
|
|
220
|
+
TParentRoute,
|
|
221
|
+
TId,
|
|
222
|
+
TCustomId,
|
|
223
|
+
TFullPath,
|
|
224
|
+
TPath,
|
|
225
|
+
TSearchValidator,
|
|
226
|
+
TParams,
|
|
227
|
+
TLoaderDeps,
|
|
228
|
+
TLoaderFn,
|
|
229
|
+
TRouterContext,
|
|
230
|
+
TRouteContextFn,
|
|
231
|
+
TBeforeLoadFn,
|
|
232
|
+
TSSR,
|
|
233
|
+
TMiddlewares,
|
|
234
|
+
THandlers
|
|
235
|
+
>,
|
|
236
|
+
) {
|
|
237
|
+
super(options)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
useMatch: UseMatchRoute<TId> = (opts) => {
|
|
241
|
+
return useMatch({
|
|
242
|
+
select: opts?.select,
|
|
243
|
+
from: this.id,
|
|
244
|
+
} as any) as any
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
useRouteContext: UseRouteContextRoute<TId> = (opts?) => {
|
|
248
|
+
return useMatch({
|
|
249
|
+
...opts,
|
|
250
|
+
from: this.id,
|
|
251
|
+
select: (d) => (opts?.select ? opts.select(d.context) : d.context),
|
|
252
|
+
}) as any
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
useSearch: UseSearchRoute<TId> = (opts) => {
|
|
256
|
+
return useSearch({
|
|
257
|
+
select: opts?.select,
|
|
258
|
+
from: this.id,
|
|
259
|
+
} as any) as any
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
useParams: UseParamsRoute<TId> = (opts) => {
|
|
263
|
+
return useParams({
|
|
264
|
+
select: opts?.select,
|
|
265
|
+
from: this.id,
|
|
266
|
+
} as any) as any
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
useLoaderDeps: UseLoaderDepsRoute<TId> = (opts) => {
|
|
270
|
+
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
useLoaderData: UseLoaderDataRoute<TId> = (opts) => {
|
|
274
|
+
return useLoaderData({ ...opts, from: this.id } as any)
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
useNavigate = (): UseNavigateResult<TFullPath> => {
|
|
278
|
+
return useNavigate({ from: this.fullPath })
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
export function createRoute<
|
|
283
|
+
TRegister = unknown,
|
|
284
|
+
TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute,
|
|
285
|
+
TPath extends RouteConstraints['TPath'] = '/',
|
|
286
|
+
TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<
|
|
287
|
+
TParentRoute,
|
|
288
|
+
TPath
|
|
289
|
+
>,
|
|
290
|
+
TCustomId extends RouteConstraints['TCustomId'] = string,
|
|
291
|
+
TId extends RouteConstraints['TId'] = ResolveId<
|
|
292
|
+
TParentRoute,
|
|
293
|
+
TCustomId,
|
|
294
|
+
TPath
|
|
295
|
+
>,
|
|
296
|
+
TSearchValidator = undefined,
|
|
297
|
+
TParams = ResolveParams<TPath>,
|
|
298
|
+
TRouteContextFn = AnyContext,
|
|
299
|
+
TBeforeLoadFn = AnyContext,
|
|
300
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
301
|
+
TLoaderFn = undefined,
|
|
302
|
+
TChildren = unknown,
|
|
303
|
+
TSSR = unknown,
|
|
304
|
+
THandlers = undefined,
|
|
305
|
+
>(
|
|
306
|
+
options: RouteOptions<
|
|
307
|
+
TRegister,
|
|
308
|
+
TParentRoute,
|
|
309
|
+
TId,
|
|
310
|
+
TCustomId,
|
|
311
|
+
TFullPath,
|
|
312
|
+
TPath,
|
|
313
|
+
TSearchValidator,
|
|
314
|
+
TParams,
|
|
315
|
+
TLoaderDeps,
|
|
316
|
+
TLoaderFn,
|
|
317
|
+
AnyContext,
|
|
318
|
+
TRouteContextFn,
|
|
319
|
+
TBeforeLoadFn,
|
|
320
|
+
TSSR,
|
|
321
|
+
THandlers
|
|
322
|
+
>,
|
|
323
|
+
): Route<
|
|
324
|
+
TRegister,
|
|
325
|
+
TParentRoute,
|
|
326
|
+
TPath,
|
|
327
|
+
TFullPath,
|
|
328
|
+
TCustomId,
|
|
329
|
+
TId,
|
|
330
|
+
TSearchValidator,
|
|
331
|
+
TParams,
|
|
332
|
+
AnyContext,
|
|
333
|
+
TRouteContextFn,
|
|
334
|
+
TBeforeLoadFn,
|
|
335
|
+
TLoaderDeps,
|
|
336
|
+
TLoaderFn,
|
|
337
|
+
TChildren,
|
|
338
|
+
unknown,
|
|
339
|
+
TSSR,
|
|
340
|
+
THandlers
|
|
341
|
+
> {
|
|
342
|
+
return new Route<
|
|
343
|
+
TRegister,
|
|
344
|
+
TParentRoute,
|
|
345
|
+
TPath,
|
|
346
|
+
TFullPath,
|
|
347
|
+
TCustomId,
|
|
348
|
+
TId,
|
|
349
|
+
TSearchValidator,
|
|
350
|
+
TParams,
|
|
351
|
+
AnyContext,
|
|
352
|
+
TRouteContextFn,
|
|
353
|
+
TBeforeLoadFn,
|
|
354
|
+
TLoaderDeps,
|
|
355
|
+
TLoaderFn,
|
|
356
|
+
TChildren,
|
|
357
|
+
unknown,
|
|
358
|
+
TSSR,
|
|
359
|
+
THandlers
|
|
360
|
+
>(options)
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
export type AnyRootRoute = RootRoute<
|
|
364
|
+
any,
|
|
365
|
+
any,
|
|
366
|
+
any,
|
|
367
|
+
any,
|
|
368
|
+
any,
|
|
369
|
+
any,
|
|
370
|
+
any,
|
|
371
|
+
any,
|
|
372
|
+
any,
|
|
373
|
+
any
|
|
374
|
+
>
|
|
375
|
+
|
|
376
|
+
export function createRootRouteWithContext<TRouterContext extends {}>() {
|
|
377
|
+
return <
|
|
378
|
+
TRegister = Register,
|
|
379
|
+
TRouteContextFn = AnyContext,
|
|
380
|
+
TBeforeLoadFn = AnyContext,
|
|
381
|
+
TSearchValidator = undefined,
|
|
382
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
383
|
+
TLoaderFn = undefined,
|
|
384
|
+
TSSR = unknown,
|
|
385
|
+
THandlers = undefined,
|
|
386
|
+
>(
|
|
387
|
+
options?: RootRouteOptions<
|
|
388
|
+
TRegister,
|
|
389
|
+
TSearchValidator,
|
|
390
|
+
TRouterContext,
|
|
391
|
+
TRouteContextFn,
|
|
392
|
+
TBeforeLoadFn,
|
|
393
|
+
TLoaderDeps,
|
|
394
|
+
TLoaderFn,
|
|
395
|
+
TSSR,
|
|
396
|
+
THandlers
|
|
397
|
+
>,
|
|
398
|
+
) => {
|
|
399
|
+
return createRootRoute<
|
|
400
|
+
TRegister,
|
|
401
|
+
TSearchValidator,
|
|
402
|
+
TRouterContext,
|
|
403
|
+
TRouteContextFn,
|
|
404
|
+
TBeforeLoadFn,
|
|
405
|
+
TLoaderDeps,
|
|
406
|
+
TLoaderFn,
|
|
407
|
+
TSSR,
|
|
408
|
+
THandlers
|
|
409
|
+
>(options as any)
|
|
410
|
+
}
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
/**
|
|
414
|
+
* @deprecated Use the `createRootRouteWithContext` function instead.
|
|
415
|
+
*/
|
|
416
|
+
export const rootRouteWithContext = createRootRouteWithContext
|
|
417
|
+
|
|
418
|
+
export class RootRoute<
|
|
419
|
+
in out TRegister = Register,
|
|
420
|
+
in out TSearchValidator = undefined,
|
|
421
|
+
in out TRouterContext = {},
|
|
422
|
+
in out TRouteContextFn = AnyContext,
|
|
423
|
+
in out TBeforeLoadFn = AnyContext,
|
|
424
|
+
in out TLoaderDeps extends Record<string, any> = {},
|
|
425
|
+
in out TLoaderFn = undefined,
|
|
426
|
+
in out TChildren = unknown,
|
|
427
|
+
in out TFileRouteTypes = unknown,
|
|
428
|
+
in out TSSR = unknown,
|
|
429
|
+
in out THandlers = undefined,
|
|
430
|
+
>
|
|
431
|
+
extends BaseRootRoute<
|
|
432
|
+
TRegister,
|
|
433
|
+
TSearchValidator,
|
|
434
|
+
TRouterContext,
|
|
435
|
+
TRouteContextFn,
|
|
436
|
+
TBeforeLoadFn,
|
|
437
|
+
TLoaderDeps,
|
|
438
|
+
TLoaderFn,
|
|
439
|
+
TChildren,
|
|
440
|
+
TFileRouteTypes,
|
|
441
|
+
TSSR,
|
|
442
|
+
THandlers
|
|
443
|
+
>
|
|
444
|
+
implements
|
|
445
|
+
RootRouteCore<
|
|
446
|
+
TRegister,
|
|
447
|
+
TSearchValidator,
|
|
448
|
+
TRouterContext,
|
|
449
|
+
TRouteContextFn,
|
|
450
|
+
TBeforeLoadFn,
|
|
451
|
+
TLoaderDeps,
|
|
452
|
+
TLoaderFn,
|
|
453
|
+
TChildren,
|
|
454
|
+
TFileRouteTypes,
|
|
455
|
+
TSSR,
|
|
456
|
+
THandlers
|
|
457
|
+
>
|
|
458
|
+
{
|
|
459
|
+
/**
|
|
460
|
+
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
461
|
+
*/
|
|
462
|
+
constructor(
|
|
463
|
+
options?: RootRouteOptions<
|
|
464
|
+
TRegister,
|
|
465
|
+
TSearchValidator,
|
|
466
|
+
TRouterContext,
|
|
467
|
+
TRouteContextFn,
|
|
468
|
+
TBeforeLoadFn,
|
|
469
|
+
TLoaderDeps,
|
|
470
|
+
TLoaderFn,
|
|
471
|
+
TSSR,
|
|
472
|
+
THandlers
|
|
473
|
+
>,
|
|
474
|
+
) {
|
|
475
|
+
super(options)
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
useMatch: UseMatchRoute<RootRouteId> = (opts) => {
|
|
479
|
+
return useMatch({
|
|
480
|
+
select: opts?.select,
|
|
481
|
+
from: this.id,
|
|
482
|
+
} as any) as any
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
useRouteContext: UseRouteContextRoute<RootRouteId> = (opts) => {
|
|
486
|
+
return useMatch({
|
|
487
|
+
...opts,
|
|
488
|
+
from: this.id,
|
|
489
|
+
select: (d) => (opts?.select ? opts.select(d.context) : d.context),
|
|
490
|
+
}) as any
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
useSearch: UseSearchRoute<RootRouteId> = (opts) => {
|
|
494
|
+
return useSearch({
|
|
495
|
+
select: opts?.select,
|
|
496
|
+
from: this.id,
|
|
497
|
+
} as any) as any
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
useParams: UseParamsRoute<RootRouteId> = (opts) => {
|
|
501
|
+
return useParams({
|
|
502
|
+
select: opts?.select,
|
|
503
|
+
from: this.id,
|
|
504
|
+
} as any) as any
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
useLoaderDeps: UseLoaderDepsRoute<RootRouteId> = (opts) => {
|
|
508
|
+
return useLoaderDeps({ ...opts, from: this.id } as any)
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
useLoaderData: UseLoaderDataRoute<RootRouteId> = (opts) => {
|
|
512
|
+
return useLoaderData({ ...opts, from: this.id } as any)
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
useNavigate = (): UseNavigateResult<'/'> => {
|
|
516
|
+
return useNavigate({ from: this.fullPath })
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
export function createRouteMask<
|
|
521
|
+
TRouteTree extends AnyRoute,
|
|
522
|
+
TFrom extends string,
|
|
523
|
+
TTo extends string,
|
|
524
|
+
>(
|
|
525
|
+
opts: {
|
|
526
|
+
routeTree: TRouteTree
|
|
527
|
+
} & ToMaskOptions<RouterCore<TRouteTree, 'never', false>, TFrom, TTo>,
|
|
528
|
+
): RouteMask<TRouteTree> {
|
|
529
|
+
return opts as any
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
export type VueNode = Vue.VNode
|
|
533
|
+
|
|
534
|
+
export type SyncRouteComponent<TProps> = (props: TProps) => Vue.VNode
|
|
535
|
+
|
|
536
|
+
export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
537
|
+
preload?: () => Promise<void>
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
export type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>
|
|
541
|
+
|
|
542
|
+
export type ErrorRouteComponent = RouteComponent<ErrorComponentProps>
|
|
543
|
+
|
|
544
|
+
export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>
|
|
545
|
+
|
|
546
|
+
export class NotFoundRoute<
|
|
547
|
+
TRegister,
|
|
548
|
+
TParentRoute extends AnyRootRoute,
|
|
549
|
+
TRouterContext = AnyContext,
|
|
550
|
+
TRouteContextFn = AnyContext,
|
|
551
|
+
TBeforeLoadFn = AnyContext,
|
|
552
|
+
TSearchValidator = undefined,
|
|
553
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
554
|
+
TLoaderFn = undefined,
|
|
555
|
+
TChildren = unknown,
|
|
556
|
+
TSSR = unknown,
|
|
557
|
+
THandlers = undefined,
|
|
558
|
+
> extends Route<
|
|
559
|
+
TRegister,
|
|
560
|
+
TParentRoute,
|
|
561
|
+
'/404',
|
|
562
|
+
'/404',
|
|
563
|
+
'404',
|
|
564
|
+
'404',
|
|
565
|
+
TSearchValidator,
|
|
566
|
+
{},
|
|
567
|
+
TRouterContext,
|
|
568
|
+
TRouteContextFn,
|
|
569
|
+
TBeforeLoadFn,
|
|
570
|
+
TLoaderDeps,
|
|
571
|
+
TLoaderFn,
|
|
572
|
+
TChildren,
|
|
573
|
+
TSSR,
|
|
574
|
+
THandlers
|
|
575
|
+
> {
|
|
576
|
+
constructor(
|
|
577
|
+
options: Omit<
|
|
578
|
+
RouteOptions<
|
|
579
|
+
TRegister,
|
|
580
|
+
TParentRoute,
|
|
581
|
+
string,
|
|
582
|
+
string,
|
|
583
|
+
string,
|
|
584
|
+
string,
|
|
585
|
+
TSearchValidator,
|
|
586
|
+
{},
|
|
587
|
+
TLoaderDeps,
|
|
588
|
+
TLoaderFn,
|
|
589
|
+
TRouterContext,
|
|
590
|
+
TRouteContextFn,
|
|
591
|
+
TBeforeLoadFn,
|
|
592
|
+
TSSR,
|
|
593
|
+
THandlers
|
|
594
|
+
>,
|
|
595
|
+
| 'caseSensitive'
|
|
596
|
+
| 'parseParams'
|
|
597
|
+
| 'stringifyParams'
|
|
598
|
+
| 'path'
|
|
599
|
+
| 'id'
|
|
600
|
+
| 'params'
|
|
601
|
+
>,
|
|
602
|
+
) {
|
|
603
|
+
super({
|
|
604
|
+
...(options as any),
|
|
605
|
+
id: '404',
|
|
606
|
+
})
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
export function createRootRoute<
|
|
611
|
+
TRegister = Register,
|
|
612
|
+
TSearchValidator = undefined,
|
|
613
|
+
TRouterContext = {},
|
|
614
|
+
TRouteContextFn = AnyContext,
|
|
615
|
+
TBeforeLoadFn = AnyContext,
|
|
616
|
+
TLoaderDeps extends Record<string, any> = {},
|
|
617
|
+
TLoaderFn = undefined,
|
|
618
|
+
TSSR = unknown,
|
|
619
|
+
THandlers = undefined,
|
|
620
|
+
>(
|
|
621
|
+
options?: RootRouteOptions<
|
|
622
|
+
TRegister,
|
|
623
|
+
TSearchValidator,
|
|
624
|
+
TRouterContext,
|
|
625
|
+
TRouteContextFn,
|
|
626
|
+
TBeforeLoadFn,
|
|
627
|
+
TLoaderDeps,
|
|
628
|
+
TLoaderFn,
|
|
629
|
+
TSSR,
|
|
630
|
+
THandlers
|
|
631
|
+
>,
|
|
632
|
+
): RootRoute<
|
|
633
|
+
TRegister,
|
|
634
|
+
TSearchValidator,
|
|
635
|
+
TRouterContext,
|
|
636
|
+
TRouteContextFn,
|
|
637
|
+
TBeforeLoadFn,
|
|
638
|
+
TLoaderDeps,
|
|
639
|
+
TLoaderFn,
|
|
640
|
+
unknown,
|
|
641
|
+
unknown,
|
|
642
|
+
TSSR,
|
|
643
|
+
THandlers
|
|
644
|
+
> {
|
|
645
|
+
return new RootRoute<
|
|
646
|
+
TRegister,
|
|
647
|
+
TSearchValidator,
|
|
648
|
+
TRouterContext,
|
|
649
|
+
TRouteContextFn,
|
|
650
|
+
TBeforeLoadFn,
|
|
651
|
+
TLoaderDeps,
|
|
652
|
+
TLoaderFn,
|
|
653
|
+
unknown,
|
|
654
|
+
unknown,
|
|
655
|
+
TSSR,
|
|
656
|
+
THandlers
|
|
657
|
+
>(options)
|
|
658
|
+
}
|