@tanstack/vue-router 1.167.1 → 1.167.2
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/esm/Asset.js +107 -151
- package/dist/esm/Asset.js.map +1 -1
- package/dist/esm/Body.js +15 -24
- package/dist/esm/Body.js.map +1 -1
- package/dist/esm/CatchBoundary.js +112 -130
- package/dist/esm/CatchBoundary.js.map +1 -1
- package/dist/esm/ClientOnly.js +59 -29
- package/dist/esm/ClientOnly.js.map +1 -1
- package/dist/esm/HeadContent.dev.js +29 -23
- package/dist/esm/HeadContent.dev.js.map +1 -1
- package/dist/esm/HeadContent.js +21 -16
- package/dist/esm/HeadContent.js.map +1 -1
- package/dist/esm/Html.js +42 -61
- package/dist/esm/Html.js.map +1 -1
- package/dist/esm/Match.js +238 -319
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/Matches.js +127 -170
- package/dist/esm/Matches.js.map +1 -1
- package/dist/esm/RouterProvider.js +50 -65
- package/dist/esm/RouterProvider.js.map +1 -1
- package/dist/esm/ScriptOnce.js +31 -36
- package/dist/esm/ScriptOnce.js.map +1 -1
- package/dist/esm/Scripts.js +79 -101
- package/dist/esm/Scripts.js.map +1 -1
- package/dist/esm/ScrollRestoration.js +25 -29
- package/dist/esm/ScrollRestoration.js.map +1 -1
- package/dist/esm/Transitioner.js +146 -164
- package/dist/esm/Transitioner.js.map +1 -1
- package/dist/esm/awaited.js +27 -34
- package/dist/esm/awaited.js.map +1 -1
- package/dist/esm/fileRoute.js +90 -92
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/headContentUtils.js +92 -123
- package/dist/esm/headContentUtils.js.map +1 -1
- package/dist/esm/index.dev.js +16 -118
- package/dist/esm/index.js +18 -119
- package/dist/esm/lazyRouteComponent.js +69 -82
- package/dist/esm/lazyRouteComponent.js.map +1 -1
- package/dist/esm/link.js +364 -385
- package/dist/esm/link.js.map +1 -1
- package/dist/esm/matchContext.js +16 -11
- package/dist/esm/matchContext.js.map +1 -1
- package/dist/esm/not-found.js +30 -40
- package/dist/esm/not-found.js.map +1 -1
- package/dist/esm/renderRouteNotFound.js +20 -15
- package/dist/esm/renderRouteNotFound.js.map +1 -1
- package/dist/esm/route.js +196 -174
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.js +11 -11
- package/dist/esm/router.js.map +1 -1
- package/dist/esm/routerContext.js +10 -7
- package/dist/esm/routerContext.js.map +1 -1
- package/dist/esm/scroll-restoration.js +39 -50
- package/dist/esm/scroll-restoration.js.map +1 -1
- package/dist/esm/ssr/RouterClient.js +29 -43
- package/dist/esm/ssr/RouterClient.js.map +1 -1
- package/dist/esm/ssr/RouterServer.js +29 -32
- package/dist/esm/ssr/RouterServer.js.map +1 -1
- package/dist/esm/ssr/client.js +1 -4
- package/dist/esm/ssr/defaultRenderHandler.js +11 -13
- package/dist/esm/ssr/defaultRenderHandler.js.map +1 -1
- package/dist/esm/ssr/defaultStreamHandler.js +12 -15
- package/dist/esm/ssr/defaultStreamHandler.js.map +1 -1
- package/dist/esm/ssr/renderRouterToStream.js +47 -65
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -1
- package/dist/esm/ssr/renderRouterToString.js +24 -32
- package/dist/esm/ssr/renderRouterToString.js.map +1 -1
- package/dist/esm/ssr/server.js +3 -10
- package/dist/esm/useBlocker.js +243 -287
- package/dist/esm/useBlocker.js.map +1 -1
- package/dist/esm/useCanGoBack.js +6 -5
- package/dist/esm/useCanGoBack.js.map +1 -1
- package/dist/esm/useLoaderData.js +12 -11
- package/dist/esm/useLoaderData.js.map +1 -1
- package/dist/esm/useLoaderDeps.js +12 -14
- package/dist/esm/useLoaderDeps.js.map +1 -1
- package/dist/esm/useLocation.js +6 -7
- package/dist/esm/useLocation.js.map +1 -1
- package/dist/esm/useMatch.js +27 -35
- package/dist/esm/useMatch.js.map +1 -1
- package/dist/esm/useNavigate.js +18 -24
- package/dist/esm/useNavigate.js.map +1 -1
- package/dist/esm/useParams.js +13 -12
- package/dist/esm/useParams.js.map +1 -1
- package/dist/esm/useRouteContext.js +9 -8
- package/dist/esm/useRouteContext.js.map +1 -1
- package/dist/esm/useRouter.js +9 -8
- package/dist/esm/useRouter.js.map +1 -1
- package/dist/esm/useRouterState.js +18 -22
- package/dist/esm/useRouterState.js.map +1 -1
- package/dist/esm/useSearch.js +13 -12
- package/dist/esm/useSearch.js.map +1 -1
- package/dist/esm/utils.js +59 -38
- package/dist/esm/utils.js.map +1 -1
- package/package.json +3 -3
- package/dist/esm/index.dev.js.map +0 -1
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/ssr/client.js.map +0 -1
- package/dist/esm/ssr/server.js.map +0 -1
package/dist/esm/Transitioner.js
CHANGED
|
@@ -1,172 +1,154 @@
|
|
|
1
|
-
import * as Vue from "vue";
|
|
2
|
-
import { trimPathRight, getLocationChangeInfo, handleHashScroll } from "@tanstack/router-core";
|
|
3
|
-
import { isServer } from "@tanstack/router-core/isServer";
|
|
4
1
|
import { useRouter } from "./useRouter.js";
|
|
5
2
|
import { useRouterState } from "./useRouterState.js";
|
|
6
3
|
import { usePrevious } from "./utils.js";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
4
|
+
import { getLocationChangeInfo, handleHashScroll, trimPathRight } from "@tanstack/router-core";
|
|
5
|
+
import * as Vue from "vue";
|
|
6
|
+
import { isServer } from "@tanstack/router-core/isServer";
|
|
7
|
+
//#region src/Transitioner.tsx
|
|
8
|
+
var mountLoadForRouter = {
|
|
9
|
+
router: null,
|
|
10
|
+
mounted: false
|
|
10
11
|
};
|
|
12
|
+
/**
|
|
13
|
+
* Composable that sets up router transition logic.
|
|
14
|
+
* This is called from MatchesContent to set up:
|
|
15
|
+
* - router.startTransition
|
|
16
|
+
* - router.startViewTransition
|
|
17
|
+
* - History subscription
|
|
18
|
+
* - Router event watchers
|
|
19
|
+
*
|
|
20
|
+
* Must be called during component setup phase.
|
|
21
|
+
*/
|
|
11
22
|
function useTransitionerSetup() {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
...getLocationChangeInfo(router.state)
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
} catch {
|
|
136
|
-
}
|
|
137
|
-
});
|
|
138
|
-
Vue.watch(isAnyPending, (newValue) => {
|
|
139
|
-
if (!isMounted.value) return;
|
|
140
|
-
try {
|
|
141
|
-
if (!newValue && router.__store.state.status === "pending") {
|
|
142
|
-
router.__store.setState((s) => ({
|
|
143
|
-
...s,
|
|
144
|
-
status: "idle",
|
|
145
|
-
resolvedLocation: s.location
|
|
146
|
-
}));
|
|
147
|
-
}
|
|
148
|
-
if (previousIsAnyPending.value.previous && !newValue) {
|
|
149
|
-
const changeInfo = getLocationChangeInfo(router.state);
|
|
150
|
-
router.emit({
|
|
151
|
-
type: "onResolved",
|
|
152
|
-
...changeInfo
|
|
153
|
-
});
|
|
154
|
-
if (changeInfo.hrefChanged) {
|
|
155
|
-
handleHashScroll(router);
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
} catch {
|
|
159
|
-
}
|
|
160
|
-
});
|
|
23
|
+
const router = useRouter();
|
|
24
|
+
if (isServer ?? router.isServer) return;
|
|
25
|
+
const isLoading = useRouterState({ select: ({ isLoading }) => isLoading });
|
|
26
|
+
const isTransitioning = Vue.ref(false);
|
|
27
|
+
const hasPendingMatches = useRouterState({ select: (s) => s.matches.some((d) => d.status === "pending") });
|
|
28
|
+
const previousIsLoading = usePrevious(() => isLoading.value);
|
|
29
|
+
const isAnyPending = Vue.computed(() => isLoading.value || isTransitioning.value || hasPendingMatches.value);
|
|
30
|
+
const previousIsAnyPending = usePrevious(() => isAnyPending.value);
|
|
31
|
+
const isPagePending = Vue.computed(() => isLoading.value || hasPendingMatches.value);
|
|
32
|
+
const previousIsPagePending = usePrevious(() => isPagePending.value);
|
|
33
|
+
router.startTransition = (fn) => {
|
|
34
|
+
isTransitioning.value = true;
|
|
35
|
+
try {
|
|
36
|
+
router.__store.setState((s) => ({
|
|
37
|
+
...s,
|
|
38
|
+
isTransitioning: true
|
|
39
|
+
}));
|
|
40
|
+
} catch {}
|
|
41
|
+
const endTransition = () => {
|
|
42
|
+
Vue.nextTick(() => {
|
|
43
|
+
try {
|
|
44
|
+
isTransitioning.value = false;
|
|
45
|
+
router.__store.setState((s) => ({
|
|
46
|
+
...s,
|
|
47
|
+
isTransitioning: false
|
|
48
|
+
}));
|
|
49
|
+
} catch {}
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
fn();
|
|
53
|
+
endTransition();
|
|
54
|
+
};
|
|
55
|
+
const originalStartViewTransition = router.__tsrOriginalStartViewTransition ?? router.startViewTransition;
|
|
56
|
+
router.__tsrOriginalStartViewTransition = originalStartViewTransition;
|
|
57
|
+
router.startViewTransition = (fn) => {
|
|
58
|
+
return originalStartViewTransition?.(async () => {
|
|
59
|
+
await fn();
|
|
60
|
+
await Vue.nextTick();
|
|
61
|
+
});
|
|
62
|
+
};
|
|
63
|
+
let unsubscribe;
|
|
64
|
+
Vue.onMounted(() => {
|
|
65
|
+
unsubscribe = router.history.subscribe(router.load);
|
|
66
|
+
const nextLocation = router.buildLocation({
|
|
67
|
+
to: router.latestLocation.pathname,
|
|
68
|
+
search: true,
|
|
69
|
+
params: true,
|
|
70
|
+
hash: true,
|
|
71
|
+
state: true,
|
|
72
|
+
_includeValidateSearch: true
|
|
73
|
+
});
|
|
74
|
+
if (trimPathRight(router.latestLocation.publicHref) !== trimPathRight(nextLocation.publicHref)) router.commitLocation({
|
|
75
|
+
...nextLocation,
|
|
76
|
+
replace: true
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
const isMounted = Vue.ref(false);
|
|
80
|
+
Vue.onMounted(() => {
|
|
81
|
+
isMounted.value = true;
|
|
82
|
+
if (!isAnyPending.value) router.__store.setState((s) => s.status === "pending" ? {
|
|
83
|
+
...s,
|
|
84
|
+
status: "idle",
|
|
85
|
+
resolvedLocation: s.location
|
|
86
|
+
} : s);
|
|
87
|
+
});
|
|
88
|
+
Vue.onUnmounted(() => {
|
|
89
|
+
isMounted.value = false;
|
|
90
|
+
if (unsubscribe) unsubscribe();
|
|
91
|
+
});
|
|
92
|
+
Vue.onMounted(() => {
|
|
93
|
+
if (typeof window !== "undefined" && router.ssr || mountLoadForRouter.router === router && mountLoadForRouter.mounted) return;
|
|
94
|
+
mountLoadForRouter = {
|
|
95
|
+
router,
|
|
96
|
+
mounted: true
|
|
97
|
+
};
|
|
98
|
+
const tryLoad = async () => {
|
|
99
|
+
try {
|
|
100
|
+
await router.load();
|
|
101
|
+
} catch (err) {
|
|
102
|
+
console.error(err);
|
|
103
|
+
}
|
|
104
|
+
};
|
|
105
|
+
tryLoad();
|
|
106
|
+
});
|
|
107
|
+
Vue.watch(() => isLoading.value, (newValue) => {
|
|
108
|
+
if (!isMounted.value) return;
|
|
109
|
+
try {
|
|
110
|
+
if (previousIsLoading.value.previous && !newValue) router.emit({
|
|
111
|
+
type: "onLoad",
|
|
112
|
+
...getLocationChangeInfo(router.state)
|
|
113
|
+
});
|
|
114
|
+
} catch {}
|
|
115
|
+
});
|
|
116
|
+
Vue.watch(isPagePending, (newValue) => {
|
|
117
|
+
if (!isMounted.value) return;
|
|
118
|
+
try {
|
|
119
|
+
if (previousIsPagePending.value.previous && !newValue) router.emit({
|
|
120
|
+
type: "onBeforeRouteMount",
|
|
121
|
+
...getLocationChangeInfo(router.state)
|
|
122
|
+
});
|
|
123
|
+
} catch {}
|
|
124
|
+
});
|
|
125
|
+
Vue.watch(isAnyPending, (newValue) => {
|
|
126
|
+
if (!isMounted.value) return;
|
|
127
|
+
try {
|
|
128
|
+
if (!newValue && router.__store.state.status === "pending") router.__store.setState((s) => ({
|
|
129
|
+
...s,
|
|
130
|
+
status: "idle",
|
|
131
|
+
resolvedLocation: s.location
|
|
132
|
+
}));
|
|
133
|
+
if (previousIsAnyPending.value.previous && !newValue) {
|
|
134
|
+
const changeInfo = getLocationChangeInfo(router.state);
|
|
135
|
+
router.emit({
|
|
136
|
+
type: "onResolved",
|
|
137
|
+
...changeInfo
|
|
138
|
+
});
|
|
139
|
+
if (changeInfo.hrefChanged) handleHashScroll(router);
|
|
140
|
+
}
|
|
141
|
+
} catch {}
|
|
142
|
+
});
|
|
161
143
|
}
|
|
162
144
|
Vue.defineComponent({
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
145
|
+
name: "Transitioner",
|
|
146
|
+
setup() {
|
|
147
|
+
useTransitionerSetup();
|
|
148
|
+
return () => null;
|
|
149
|
+
}
|
|
168
150
|
});
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
//# sourceMappingURL=Transitioner.js.map
|
|
151
|
+
//#endregion
|
|
152
|
+
export { useTransitionerSetup };
|
|
153
|
+
|
|
154
|
+
//# sourceMappingURL=Transitioner.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transitioner.js","sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Vue from 'vue'\nimport {\n getLocationChangeInfo,\n handleHashScroll,\n trimPathRight,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport { usePrevious } from './utils'\n\n// Track mount state per router to avoid double-loading\nlet mountLoadForRouter = { router: null as any, mounted: false }\n\n/**\n * Composable that sets up router transition logic.\n * This is called from MatchesContent to set up:\n * - router.startTransition\n * - router.startViewTransition\n * - History subscription\n * - Router event watchers\n *\n * Must be called during component setup phase.\n */\nexport function useTransitionerSetup() {\n const router = useRouter()\n\n // Skip on server - no transitions needed\n if (isServer ?? router.isServer) {\n return\n }\n\n const isLoading = useRouterState({\n select: ({ isLoading }) => isLoading,\n })\n\n // Track if we're in a transition - using a ref to track async transitions\n const isTransitioning = Vue.ref(false)\n\n // Track pending state changes\n const hasPendingMatches = useRouterState({\n select: (s) => s.matches.some((d) => d.status === 'pending'),\n })\n\n const previousIsLoading = usePrevious(() => isLoading.value)\n\n const isAnyPending = Vue.computed(\n () => isLoading.value || isTransitioning.value || hasPendingMatches.value,\n )\n const previousIsAnyPending = usePrevious(() => isAnyPending.value)\n\n const isPagePending = Vue.computed(\n () => isLoading.value || hasPendingMatches.value,\n )\n const previousIsPagePending = usePrevious(() => isPagePending.value)\n\n // Implement startTransition similar to React/Solid\n // Vue doesn't have a native useTransition like React 18, so we simulate it\n // We also update the router state's isTransitioning flag so useMatch can check it\n router.startTransition = (fn: () => void | Promise<void>) => {\n isTransitioning.value = true\n // Also update the router state so useMatch knows we're transitioning\n try {\n router.__store.setState((s) => ({ ...s, isTransitioning: true }))\n } catch {\n // Ignore errors if component is unmounted\n }\n\n // Helper to end the transition\n const endTransition = () => {\n // Use nextTick to ensure Vue has processed all reactive updates\n Vue.nextTick(() => {\n try {\n isTransitioning.value = false\n router.__store.setState((s) => ({ ...s, isTransitioning: false }))\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n }\n\n // Execute the function synchronously\n // The function internally may call startViewTransition which schedules async work\n // via document.startViewTransition, but we don't need to wait for it here\n // because Vue's reactivity will trigger re-renders when state changes\n fn()\n\n // End the transition on next tick to allow Vue to process reactive updates\n endTransition()\n }\n\n // Vue updates DOM asynchronously (next tick). The View Transitions API expects the\n // update callback promise to resolve only after the DOM has been updated.\n // Wrap the router-core implementation to await a Vue flush before resolving.\n const originalStartViewTransition:\n | undefined\n | ((fn: () => Promise<void>) => void) =\n (router as any).__tsrOriginalStartViewTransition ??\n router.startViewTransition\n\n ;(router as any).__tsrOriginalStartViewTransition =\n originalStartViewTransition\n\n router.startViewTransition = (fn: () => Promise<void>) => {\n return originalStartViewTransition?.(async () => {\n await fn()\n await Vue.nextTick()\n })\n }\n\n // Subscribe to location changes\n // and try to load the new location\n let unsubscribe: (() => void) | undefined\n\n Vue.onMounted(() => {\n unsubscribe = router.history.subscribe(router.load)\n\n const nextLocation = router.buildLocation({\n to: router.latestLocation.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n\n // Check if the current URL matches the canonical form.\n // Compare publicHref (browser-facing URL) for consistency with\n // the server-side redirect check in router.beforeLoad.\n if (\n trimPathRight(router.latestLocation.publicHref) !==\n trimPathRight(nextLocation.publicHref)\n ) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n })\n\n // Track if component is mounted to prevent updates after unmount\n const isMounted = Vue.ref(false)\n\n Vue.onMounted(() => {\n isMounted.value = true\n if (!isAnyPending.value) {\n router.__store.setState((s) =>\n s.status === 'pending'\n ? { ...s, status: 'idle', resolvedLocation: s.location }\n : s,\n )\n }\n })\n\n Vue.onUnmounted(() => {\n isMounted.value = false\n if (unsubscribe) {\n unsubscribe()\n }\n })\n\n // Try to load the initial location\n Vue.onMounted(() => {\n if (\n (typeof window !== 'undefined' && router.ssr) ||\n (mountLoadForRouter.router === router && mountLoadForRouter.mounted)\n ) {\n return\n }\n mountLoadForRouter = { router, mounted: true }\n const tryLoad = async () => {\n try {\n await router.load()\n } catch (err) {\n console.error(err)\n }\n }\n tryLoad()\n })\n\n // Setup watchers for emitting events\n // All watchers check isMounted to prevent updates after unmount\n Vue.watch(\n () => isLoading.value,\n (newValue) => {\n if (!isMounted.value) return\n try {\n if (previousIsLoading.value.previous && !newValue) {\n router.emit({\n type: 'onLoad',\n ...getLocationChangeInfo(router.state),\n })\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n },\n )\n\n Vue.watch(isPagePending, (newValue) => {\n if (!isMounted.value) return\n try {\n // emit onBeforeRouteMount\n if (previousIsPagePending.value.previous && !newValue) {\n router.emit({\n type: 'onBeforeRouteMount',\n ...getLocationChangeInfo(router.state),\n })\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n\n Vue.watch(isAnyPending, (newValue) => {\n if (!isMounted.value) return\n try {\n if (!newValue && router.__store.state.status === 'pending') {\n router.__store.setState((s) => ({\n ...s,\n status: 'idle',\n resolvedLocation: s.location,\n }))\n }\n\n // The router was pending and now it's not\n if (previousIsAnyPending.value.previous && !newValue) {\n const changeInfo = getLocationChangeInfo(router.state)\n router.emit({\n type: 'onResolved',\n ...changeInfo,\n })\n\n if (changeInfo.hrefChanged) {\n handleHashScroll(router)\n }\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n}\n\n/**\n * @deprecated Use useTransitionerSetup() composable instead.\n * This component is kept for backwards compatibility but the setup logic\n * has been moved to useTransitionerSetup() for better SSR hydration.\n */\nexport const Transitioner = Vue.defineComponent({\n name: 'Transitioner',\n setup() {\n useTransitionerSetup()\n return () => null\n },\n})\n"],"names":["mountLoadForRouter","router","mounted","useTransitionerSetup","useRouter","isServer","isLoading","useRouterState","select","isTransitioning","Vue","ref","hasPendingMatches","s","matches","some","d","status","previousIsLoading","usePrevious","value","isAnyPending","computed","previousIsAnyPending","isPagePending","previousIsPagePending","startTransition","fn","__store","setState","endTransition","nextTick","originalStartViewTransition","__tsrOriginalStartViewTransition","startViewTransition","unsubscribe","onMounted","history","subscribe","load","nextLocation","buildLocation","to","latestLocation","pathname","search","params","hash","state","_includeValidateSearch","trimPathRight","publicHref","commitLocation","replace","isMounted","resolvedLocation","location","onUnmounted","window","ssr","tryLoad","err","console","error","watch","newValue","previous","emit","type","getLocationChangeInfo","changeInfo","hrefChanged","handleHashScroll","defineComponent","name","setup"],"mappings":";;;;;;AAYA,IAAIA,qBAAqB;AAAA,EAAEC,QAAQ;AAAA,EAAaC,SAAS;AAAM;AAYxD,SAASC,uBAAuB;AACrC,QAAMF,SAASG,UAAS;AAGxB,MAAIC,YAAYJ,OAAOI,UAAU;AAC/B;AAAA,EACF;AAEA,QAAMC,YAAYC,eAAe;AAAA,IAC/BC,QAAQA,CAAC;A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,IAAI+D,gBAAgB;AAAA,EAC9CC,MAAM;AAAA,EACNC,QAAQ;AACNxE,yBAAoB;AACpB,WAAO,MAAM;AAAA,EACf;AACF,CAAC;"}
|
|
1
|
+
{"version":3,"file":"Transitioner.js","names":["Vue","getLocationChangeInfo","handleHashScroll","trimPathRight","isServer","useRouter","useRouterState","usePrevious","mountLoadForRouter","router","mounted","useTransitionerSetup","isLoading","select","isTransitioning","ref","hasPendingMatches","s","matches","some","d","status","previousIsLoading","value","isAnyPending","computed","previousIsAnyPending","isPagePending","previousIsPagePending","startTransition","fn","__store","setState","endTransition","nextTick","originalStartViewTransition","__tsrOriginalStartViewTransition","startViewTransition","unsubscribe","onMounted","history","subscribe","load","nextLocation","buildLocation","to","latestLocation","pathname","search","params","hash","state","_includeValidateSearch","publicHref","commitLocation","replace","isMounted","resolvedLocation","location","onUnmounted","window","ssr","tryLoad","err","console","error","watch","newValue","previous","emit","type","changeInfo","hrefChanged","Transitioner","defineComponent","name","setup"],"sources":["../../src/Transitioner.tsx"],"sourcesContent":["import * as Vue from 'vue'\nimport {\n getLocationChangeInfo,\n handleHashScroll,\n trimPathRight,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { useRouter } from './useRouter'\nimport { useRouterState } from './useRouterState'\nimport { usePrevious } from './utils'\n\n// Track mount state per router to avoid double-loading\nlet mountLoadForRouter = { router: null as any, mounted: false }\n\n/**\n * Composable that sets up router transition logic.\n * This is called from MatchesContent to set up:\n * - router.startTransition\n * - router.startViewTransition\n * - History subscription\n * - Router event watchers\n *\n * Must be called during component setup phase.\n */\nexport function useTransitionerSetup() {\n const router = useRouter()\n\n // Skip on server - no transitions needed\n if (isServer ?? router.isServer) {\n return\n }\n\n const isLoading = useRouterState({\n select: ({ isLoading }) => isLoading,\n })\n\n // Track if we're in a transition - using a ref to track async transitions\n const isTransitioning = Vue.ref(false)\n\n // Track pending state changes\n const hasPendingMatches = useRouterState({\n select: (s) => s.matches.some((d) => d.status === 'pending'),\n })\n\n const previousIsLoading = usePrevious(() => isLoading.value)\n\n const isAnyPending = Vue.computed(\n () => isLoading.value || isTransitioning.value || hasPendingMatches.value,\n )\n const previousIsAnyPending = usePrevious(() => isAnyPending.value)\n\n const isPagePending = Vue.computed(\n () => isLoading.value || hasPendingMatches.value,\n )\n const previousIsPagePending = usePrevious(() => isPagePending.value)\n\n // Implement startTransition similar to React/Solid\n // Vue doesn't have a native useTransition like React 18, so we simulate it\n // We also update the router state's isTransitioning flag so useMatch can check it\n router.startTransition = (fn: () => void | Promise<void>) => {\n isTransitioning.value = true\n // Also update the router state so useMatch knows we're transitioning\n try {\n router.__store.setState((s) => ({ ...s, isTransitioning: true }))\n } catch {\n // Ignore errors if component is unmounted\n }\n\n // Helper to end the transition\n const endTransition = () => {\n // Use nextTick to ensure Vue has processed all reactive updates\n Vue.nextTick(() => {\n try {\n isTransitioning.value = false\n router.__store.setState((s) => ({ ...s, isTransitioning: false }))\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n }\n\n // Execute the function synchronously\n // The function internally may call startViewTransition which schedules async work\n // via document.startViewTransition, but we don't need to wait for it here\n // because Vue's reactivity will trigger re-renders when state changes\n fn()\n\n // End the transition on next tick to allow Vue to process reactive updates\n endTransition()\n }\n\n // Vue updates DOM asynchronously (next tick). The View Transitions API expects the\n // update callback promise to resolve only after the DOM has been updated.\n // Wrap the router-core implementation to await a Vue flush before resolving.\n const originalStartViewTransition:\n | undefined\n | ((fn: () => Promise<void>) => void) =\n (router as any).__tsrOriginalStartViewTransition ??\n router.startViewTransition\n\n ;(router as any).__tsrOriginalStartViewTransition =\n originalStartViewTransition\n\n router.startViewTransition = (fn: () => Promise<void>) => {\n return originalStartViewTransition?.(async () => {\n await fn()\n await Vue.nextTick()\n })\n }\n\n // Subscribe to location changes\n // and try to load the new location\n let unsubscribe: (() => void) | undefined\n\n Vue.onMounted(() => {\n unsubscribe = router.history.subscribe(router.load)\n\n const nextLocation = router.buildLocation({\n to: router.latestLocation.pathname,\n search: true,\n params: true,\n hash: true,\n state: true,\n _includeValidateSearch: true,\n })\n\n // Check if the current URL matches the canonical form.\n // Compare publicHref (browser-facing URL) for consistency with\n // the server-side redirect check in router.beforeLoad.\n if (\n trimPathRight(router.latestLocation.publicHref) !==\n trimPathRight(nextLocation.publicHref)\n ) {\n router.commitLocation({ ...nextLocation, replace: true })\n }\n })\n\n // Track if component is mounted to prevent updates after unmount\n const isMounted = Vue.ref(false)\n\n Vue.onMounted(() => {\n isMounted.value = true\n if (!isAnyPending.value) {\n router.__store.setState((s) =>\n s.status === 'pending'\n ? { ...s, status: 'idle', resolvedLocation: s.location }\n : s,\n )\n }\n })\n\n Vue.onUnmounted(() => {\n isMounted.value = false\n if (unsubscribe) {\n unsubscribe()\n }\n })\n\n // Try to load the initial location\n Vue.onMounted(() => {\n if (\n (typeof window !== 'undefined' && router.ssr) ||\n (mountLoadForRouter.router === router && mountLoadForRouter.mounted)\n ) {\n return\n }\n mountLoadForRouter = { router, mounted: true }\n const tryLoad = async () => {\n try {\n await router.load()\n } catch (err) {\n console.error(err)\n }\n }\n tryLoad()\n })\n\n // Setup watchers for emitting events\n // All watchers check isMounted to prevent updates after unmount\n Vue.watch(\n () => isLoading.value,\n (newValue) => {\n if (!isMounted.value) return\n try {\n if (previousIsLoading.value.previous && !newValue) {\n router.emit({\n type: 'onLoad',\n ...getLocationChangeInfo(router.state),\n })\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n },\n )\n\n Vue.watch(isPagePending, (newValue) => {\n if (!isMounted.value) return\n try {\n // emit onBeforeRouteMount\n if (previousIsPagePending.value.previous && !newValue) {\n router.emit({\n type: 'onBeforeRouteMount',\n ...getLocationChangeInfo(router.state),\n })\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n\n Vue.watch(isAnyPending, (newValue) => {\n if (!isMounted.value) return\n try {\n if (!newValue && router.__store.state.status === 'pending') {\n router.__store.setState((s) => ({\n ...s,\n status: 'idle',\n resolvedLocation: s.location,\n }))\n }\n\n // The router was pending and now it's not\n if (previousIsAnyPending.value.previous && !newValue) {\n const changeInfo = getLocationChangeInfo(router.state)\n router.emit({\n type: 'onResolved',\n ...changeInfo,\n })\n\n if (changeInfo.hrefChanged) {\n handleHashScroll(router)\n }\n }\n } catch {\n // Ignore errors if component is unmounted\n }\n })\n}\n\n/**\n * @deprecated Use useTransitionerSetup() composable instead.\n * This component is kept for backwards compatibility but the setup logic\n * has been moved to useTransitionerSetup() for better SSR hydration.\n */\nexport const Transitioner = Vue.defineComponent({\n name: 'Transitioner',\n setup() {\n useTransitionerSetup()\n return () => null\n },\n})\n"],"mappings":";;;;;;;AAYA,IAAIQ,qBAAqB;CAAEC,QAAQ;CAAaC,SAAS;CAAO;;;;;;;;;;;AAYhE,SAAgBC,uBAAuB;CACrC,MAAMF,SAASJ,WAAW;AAG1B,KAAID,YAAYK,OAAOL,SACrB;CAGF,MAAMQ,YAAYN,eAAe,EAC/BO,SAAS,EAAED,gBAAgBA,WAC5B,CAAC;CAGF,MAAME,kBAAkBd,IAAIe,IAAI,MAAM;CAGtC,MAAMC,oBAAoBV,eAAe,EACvCO,SAASI,MAAMA,EAAEC,QAAQC,MAAMC,MAAMA,EAAEC,WAAW,UAAS,EAC5D,CAAC;CAEF,MAAMC,oBAAoBf,kBAAkBK,UAAUW,MAAM;CAE5D,MAAMC,eAAexB,IAAIyB,eACjBb,UAAUW,SAAST,gBAAgBS,SAASP,kBAAkBO,MACrE;CACD,MAAMG,uBAAuBnB,kBAAkBiB,aAAaD,MAAM;CAElE,MAAMI,gBAAgB3B,IAAIyB,eAClBb,UAAUW,SAASP,kBAAkBO,MAC5C;CACD,MAAMK,wBAAwBrB,kBAAkBoB,cAAcJ,MAAM;AAKpEd,QAAOoB,mBAAmBC,OAAmC;AAC3DhB,kBAAgBS,QAAQ;AAExB,MAAI;AACFd,UAAOsB,QAAQC,UAAUf,OAAO;IAAE,GAAGA;IAAGH,iBAAiB;IAAM,EAAE;UAC3D;EAKR,MA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
import { TSR_DEFERRED_PROMISE, defer } from "@tanstack/router-core";
|
|
1
2
|
import * as Vue from "vue";
|
|
2
|
-
|
|
3
|
-
function useAwaited({
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
throw promise;
|
|
9
|
-
}
|
|
10
|
-
if (promise[TSR_DEFERRED_PROMISE].status === "error") {
|
|
11
|
-
throw promise[TSR_DEFERRED_PROMISE].error;
|
|
12
|
-
}
|
|
13
|
-
return [promise[TSR_DEFERRED_PROMISE].data, promise];
|
|
3
|
+
//#region src/awaited.tsx
|
|
4
|
+
function useAwaited({ promise: _promise }) {
|
|
5
|
+
const promise = defer(_promise);
|
|
6
|
+
if (promise[TSR_DEFERRED_PROMISE].status === "pending") throw promise;
|
|
7
|
+
if (promise[TSR_DEFERRED_PROMISE].status === "error") throw promise[TSR_DEFERRED_PROMISE].error;
|
|
8
|
+
return [promise[TSR_DEFERRED_PROMISE].data, promise];
|
|
14
9
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
10
|
+
var Await = Vue.defineComponent({
|
|
11
|
+
name: "Await",
|
|
12
|
+
props: {
|
|
13
|
+
promise: {
|
|
14
|
+
type: Promise,
|
|
15
|
+
required: true
|
|
16
|
+
},
|
|
17
|
+
children: {
|
|
18
|
+
type: Function,
|
|
19
|
+
required: true
|
|
20
|
+
}
|
|
21
|
+
},
|
|
22
|
+
async setup(props) {
|
|
23
|
+
const data = await defer(props.promise);
|
|
24
|
+
return () => props.children(data);
|
|
25
|
+
}
|
|
32
26
|
});
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
//# sourceMappingURL=awaited.js.map
|
|
27
|
+
//#endregion
|
|
28
|
+
export { Await, useAwaited };
|
|
29
|
+
|
|
30
|
+
//# sourceMappingURL=awaited.js.map
|
package/dist/esm/awaited.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"awaited.js","sources":["../../src/awaited.tsx"],"sourcesContent":["import * as Vue from 'vue'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\nimport type { DeferredPromise } from '@tanstack/router-core'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\nexport function useAwaited<T>({\n promise: _promise,\n}: AwaitOptions<T>): [T, DeferredPromise<T>] {\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return [promise[TSR_DEFERRED_PROMISE].data, promise]\n}\n\nexport const Await = Vue.defineComponent({\n name: 'Await',\n props: {\n promise: {\n type: Promise,\n required: true,\n },\n children: {\n type: Function,\n required: true,\n },\n },\n async setup(props) {\n const deferred = defer(props.promise)\n const data = await deferred\n return () => (props.children as (result: unknown) => Vue.VNode)(data)\n },\n})\n"],"
|
|
1
|
+
{"version":3,"file":"awaited.js","names":["Vue","TSR_DEFERRED_PROMISE","defer","useAwaited","promise","_promise","status","error","data","Await","defineComponent","name","props","type","Promise","required","children","Function","setup","deferred"],"sources":["../../src/awaited.tsx"],"sourcesContent":["import * as Vue from 'vue'\n\nimport { TSR_DEFERRED_PROMISE, defer } from '@tanstack/router-core'\nimport type { DeferredPromise } from '@tanstack/router-core'\n\nexport type AwaitOptions<T> = {\n promise: Promise<T>\n}\n\nexport function useAwaited<T>({\n promise: _promise,\n}: AwaitOptions<T>): [T, DeferredPromise<T>] {\n const promise = defer(_promise)\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'pending') {\n throw promise\n }\n\n if (promise[TSR_DEFERRED_PROMISE].status === 'error') {\n throw promise[TSR_DEFERRED_PROMISE].error\n }\n\n return [promise[TSR_DEFERRED_PROMISE].data, promise]\n}\n\nexport const Await = Vue.defineComponent({\n name: 'Await',\n props: {\n promise: {\n type: Promise,\n required: true,\n },\n children: {\n type: Function,\n required: true,\n },\n },\n async setup(props) {\n const deferred = defer(props.promise)\n const data = await deferred\n return () => (props.children as (result: unknown) => Vue.VNode)(data)\n },\n})\n"],"mappings":";;;AASA,SAAgBG,WAAc,EAC5BC,SAASC,YACkC;CAC3C,MAAMD,UAAUF,MAAMG,SAAS;AAE/B,KAAID,QAAQH,sBAAsBK,WAAW,UAC3C,OAAMF;AAGR,KAAIA,QAAQH,sBAAsBK,WAAW,QAC3C,OAAMF,QAAQH,sBAAsBM;AAGtC,QAAO,CAACH,QAAQH,sBAAsBO,MAAMJ,QAAQ;;AAGtD,IAAaK,QAAQT,IAAIU,gBAAgB;CACvCC,MAAM;CACNC,OAAO;EACLR,SAAS;GACPS,MAAMC;GACNC,UAAU;GACX;EACDC,UAAU;GACRH,MAAMI;GACNF,UAAU;GACZ;EACD;CACD,MAAMG,MAAMN,OAAO;EAEjB,MAAMJ,OAAO,MADIN,MAAMU,MAAMR,QAAQ;AAErC,eAAcQ,MAAMI,SAA4CR,KAAK;;CAExE,CAAC"}
|
package/dist/esm/fileRoute.js
CHANGED
|
@@ -1,105 +1,103 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { createRoute } from "./route.js";
|
|
1
|
+
import { useRouter } from "./useRouter.js";
|
|
3
2
|
import { useMatch } from "./useMatch.js";
|
|
4
|
-
import { useLoaderDeps } from "./useLoaderDeps.js";
|
|
5
3
|
import { useLoaderData } from "./useLoaderData.js";
|
|
6
|
-
import {
|
|
4
|
+
import { useLoaderDeps } from "./useLoaderDeps.js";
|
|
7
5
|
import { useParams } from "./useParams.js";
|
|
6
|
+
import { useSearch } from "./useSearch.js";
|
|
8
7
|
import { useNavigate } from "./useNavigate.js";
|
|
9
|
-
import { useRouter } from "./useRouter.js";
|
|
10
8
|
import { useRouteContext } from "./useRouteContext.js";
|
|
9
|
+
import { createRoute } from "./route.js";
|
|
10
|
+
import warning from "tiny-warning";
|
|
11
|
+
//#region src/fileRoute.ts
|
|
11
12
|
function createFileRoute(path) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
silent: true
|
|
15
|
-
}).createRoute(path);
|
|
16
|
-
}
|
|
17
|
-
return new FileRoute(path, {
|
|
18
|
-
silent: true
|
|
19
|
-
}).createRoute;
|
|
20
|
-
}
|
|
21
|
-
class FileRoute {
|
|
22
|
-
constructor(path, _opts) {
|
|
23
|
-
this.path = path;
|
|
24
|
-
this.createRoute = (options) => {
|
|
25
|
-
if (process.env.NODE_ENV !== "production") {
|
|
26
|
-
warning(
|
|
27
|
-
this.silent,
|
|
28
|
-
"FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead."
|
|
29
|
-
);
|
|
30
|
-
}
|
|
31
|
-
const route = createRoute(options);
|
|
32
|
-
route.isRoot = false;
|
|
33
|
-
return route;
|
|
34
|
-
};
|
|
35
|
-
this.silent = _opts?.silent;
|
|
36
|
-
}
|
|
13
|
+
if (typeof path === "object") return new FileRoute(path, { silent: true }).createRoute(path);
|
|
14
|
+
return new FileRoute(path, { silent: true }).createRoute;
|
|
37
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
@deprecated It's no longer recommended to use the `FileRoute` class directly.
|
|
18
|
+
Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.
|
|
19
|
+
*/
|
|
20
|
+
var FileRoute = class {
|
|
21
|
+
constructor(path, _opts) {
|
|
22
|
+
this.path = path;
|
|
23
|
+
this.createRoute = (options) => {
|
|
24
|
+
if (process.env.NODE_ENV !== "production") warning(this.silent, "FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.");
|
|
25
|
+
const route = createRoute(options);
|
|
26
|
+
route.isRoot = false;
|
|
27
|
+
return route;
|
|
28
|
+
};
|
|
29
|
+
this.silent = _opts?.silent;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
@deprecated It's recommended not to split loaders into separate files.
|
|
34
|
+
Instead, place the loader function in the the main route file, inside the
|
|
35
|
+
`createFileRoute('/path/to/file)(options)` options.
|
|
36
|
+
*/
|
|
38
37
|
function FileRouteLoader(_path) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
false,
|
|
42
|
-
`FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`
|
|
43
|
-
);
|
|
44
|
-
}
|
|
45
|
-
return (loaderFn) => loaderFn;
|
|
46
|
-
}
|
|
47
|
-
class LazyRoute {
|
|
48
|
-
constructor(opts) {
|
|
49
|
-
this.useMatch = (opts2) => {
|
|
50
|
-
return useMatch({
|
|
51
|
-
select: opts2?.select,
|
|
52
|
-
from: this.options.id
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
this.useRouteContext = (opts2) => {
|
|
56
|
-
return useRouteContext({ ...opts2, from: this.options.id });
|
|
57
|
-
};
|
|
58
|
-
this.useSearch = (opts2) => {
|
|
59
|
-
return useSearch({
|
|
60
|
-
select: opts2?.select,
|
|
61
|
-
from: this.options.id
|
|
62
|
-
});
|
|
63
|
-
};
|
|
64
|
-
this.useParams = (opts2) => {
|
|
65
|
-
return useParams({
|
|
66
|
-
select: opts2?.select,
|
|
67
|
-
from: this.options.id
|
|
68
|
-
});
|
|
69
|
-
};
|
|
70
|
-
this.useLoaderDeps = (opts2) => {
|
|
71
|
-
return useLoaderDeps({ ...opts2, from: this.options.id });
|
|
72
|
-
};
|
|
73
|
-
this.useLoaderData = (opts2) => {
|
|
74
|
-
return useLoaderData({ ...opts2, from: this.options.id });
|
|
75
|
-
};
|
|
76
|
-
this.useNavigate = () => {
|
|
77
|
-
const router = useRouter();
|
|
78
|
-
return useNavigate({ from: router.routesById[this.options.id].fullPath });
|
|
79
|
-
};
|
|
80
|
-
this.options = opts;
|
|
81
|
-
}
|
|
38
|
+
if (process.env.NODE_ENV !== "production") warning(false, `FileRouteLoader is deprecated and will be removed in the next major version. Please place the loader function in the the main route file, inside the \`createFileRoute('/path/to/file')(options)\` options`);
|
|
39
|
+
return (loaderFn) => loaderFn;
|
|
82
40
|
}
|
|
41
|
+
var LazyRoute = class {
|
|
42
|
+
constructor(opts) {
|
|
43
|
+
this.useMatch = (opts) => {
|
|
44
|
+
return useMatch({
|
|
45
|
+
select: opts?.select,
|
|
46
|
+
from: this.options.id
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
this.useRouteContext = (opts) => {
|
|
50
|
+
return useRouteContext({
|
|
51
|
+
...opts,
|
|
52
|
+
from: this.options.id
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
this.useSearch = (opts) => {
|
|
56
|
+
return useSearch({
|
|
57
|
+
select: opts?.select,
|
|
58
|
+
from: this.options.id
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
this.useParams = (opts) => {
|
|
62
|
+
return useParams({
|
|
63
|
+
select: opts?.select,
|
|
64
|
+
from: this.options.id
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
this.useLoaderDeps = (opts) => {
|
|
68
|
+
return useLoaderDeps({
|
|
69
|
+
...opts,
|
|
70
|
+
from: this.options.id
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
this.useLoaderData = (opts) => {
|
|
74
|
+
return useLoaderData({
|
|
75
|
+
...opts,
|
|
76
|
+
from: this.options.id
|
|
77
|
+
});
|
|
78
|
+
};
|
|
79
|
+
this.useNavigate = () => {
|
|
80
|
+
return useNavigate({ from: useRouter().routesById[this.options.id].fullPath });
|
|
81
|
+
};
|
|
82
|
+
this.options = opts;
|
|
83
|
+
}
|
|
84
|
+
};
|
|
83
85
|
function createLazyRoute(id) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
return (opts) => {
|
|
87
|
+
return new LazyRoute({
|
|
88
|
+
id,
|
|
89
|
+
...opts
|
|
90
|
+
});
|
|
91
|
+
};
|
|
90
92
|
}
|
|
91
93
|
function createLazyFileRoute(id) {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
94
|
+
if (typeof id === "object") return new LazyRoute(id);
|
|
95
|
+
return (opts) => new LazyRoute({
|
|
96
|
+
id,
|
|
97
|
+
...opts
|
|
98
|
+
});
|
|
96
99
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
createFileRoute,
|
|
102
|
-
createLazyFileRoute,
|
|
103
|
-
createLazyRoute
|
|
104
|
-
};
|
|
105
|
-
//# sourceMappingURL=fileRoute.js.map
|
|
100
|
+
//#endregion
|
|
101
|
+
export { FileRoute, FileRouteLoader, LazyRoute, createFileRoute, createLazyFileRoute, createLazyRoute };
|
|
102
|
+
|
|
103
|
+
//# sourceMappingURL=fileRoute.js.map
|