@tanstack/react-router 1.47.4 → 1.48.0
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/Match.cjs +29 -51
- package/dist/cjs/Match.cjs.map +1 -1
- package/dist/cjs/fileRoute.cjs.map +1 -1
- package/dist/cjs/fileRoute.d.cts +3 -3
- package/dist/cjs/index.d.cts +1 -1
- package/dist/cjs/route.cjs.map +1 -1
- package/dist/cjs/route.d.cts +64 -67
- package/dist/cjs/router.cjs.map +1 -1
- package/dist/cjs/router.d.cts +1 -1
- package/dist/esm/Match.js +29 -51
- package/dist/esm/Match.js.map +1 -1
- package/dist/esm/fileRoute.d.ts +3 -3
- package/dist/esm/fileRoute.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/route.d.ts +64 -67
- package/dist/esm/route.js.map +1 -1
- package/dist/esm/router.d.ts +1 -1
- package/dist/esm/router.js.map +1 -1
- package/package.json +1 -1
- package/src/Match.tsx +37 -58
- package/src/fileRoute.ts +10 -25
- package/src/index.tsx +1 -3
- package/src/route.ts +202 -202
- package/src/router.ts +0 -2
package/dist/esm/Match.js
CHANGED
|
@@ -74,66 +74,25 @@ const Match = React.memo(function MatchImpl({
|
|
|
74
74
|
const MatchInner = React.memo(function MatchInnerImpl({
|
|
75
75
|
matchId
|
|
76
76
|
}) {
|
|
77
|
-
var _a, _b;
|
|
77
|
+
var _a, _b, _c;
|
|
78
78
|
const router = useRouter();
|
|
79
|
-
const routeId = useRouterState({
|
|
79
|
+
const { match, matchIndex, routeId } = useRouterState({
|
|
80
80
|
select: (s) => {
|
|
81
|
-
|
|
82
|
-
|
|
81
|
+
const matchIndex2 = s.matches.findIndex((d) => d.id === matchId);
|
|
82
|
+
const match2 = s.matches[matchIndex2];
|
|
83
|
+
const routeId2 = match2.routeId;
|
|
84
|
+
return {
|
|
85
|
+
routeId: routeId2,
|
|
86
|
+
matchIndex: matchIndex2,
|
|
87
|
+
match: pick(match2, ["id", "status", "error", "loadPromise"])
|
|
88
|
+
};
|
|
83
89
|
}
|
|
84
90
|
});
|
|
85
91
|
const route = router.routesById[routeId];
|
|
86
|
-
const matchIndex = useRouterState({
|
|
87
|
-
select: (s) => {
|
|
88
|
-
return s.matches.findIndex((d) => d.id === matchId);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
const match = useRouterState({
|
|
92
|
-
select: (s) => {
|
|
93
|
-
const match2 = s.matches[matchIndex];
|
|
94
|
-
return pick(match2, [
|
|
95
|
-
"id",
|
|
96
|
-
"status",
|
|
97
|
-
"error",
|
|
98
|
-
"loadPromise",
|
|
99
|
-
"minPendingPromise"
|
|
100
|
-
]);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
92
|
const out = React.useMemo(() => {
|
|
104
93
|
const Comp = route.options.component ?? router.options.defaultComponent;
|
|
105
94
|
return Comp ? /* @__PURE__ */ jsx(Comp, {}, routeId) : /* @__PURE__ */ jsx(Outlet, {});
|
|
106
95
|
}, [routeId, route.options.component, router.options.defaultComponent]);
|
|
107
|
-
React.useEffect(() => {
|
|
108
|
-
if (match.status === "pending") {
|
|
109
|
-
const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
|
|
110
|
-
if (pendingMinMs && !match.minPendingPromise) {
|
|
111
|
-
if (!router.isServer) {
|
|
112
|
-
const minPendingPromise = createControlledPromise();
|
|
113
|
-
router.updateMatch(match.id, (prev) => ({
|
|
114
|
-
...prev,
|
|
115
|
-
minPendingPromise
|
|
116
|
-
}));
|
|
117
|
-
const id = setTimeout(() => {
|
|
118
|
-
minPendingPromise.resolve();
|
|
119
|
-
router.updateMatch(match.id, (prev) => ({
|
|
120
|
-
...prev,
|
|
121
|
-
minPendingPromise: void 0
|
|
122
|
-
}));
|
|
123
|
-
}, pendingMinMs);
|
|
124
|
-
return () => clearTimeout(id);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return void 0;
|
|
129
|
-
}, [
|
|
130
|
-
match.id,
|
|
131
|
-
match.loadPromise,
|
|
132
|
-
match.minPendingPromise,
|
|
133
|
-
match.status,
|
|
134
|
-
route.options.pendingMinMs,
|
|
135
|
-
router
|
|
136
|
-
]);
|
|
137
96
|
const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
|
|
138
97
|
if (match.status === "notFound") {
|
|
139
98
|
let error;
|
|
@@ -170,6 +129,25 @@ const MatchInner = React.memo(function MatchInnerImpl({
|
|
|
170
129
|
}
|
|
171
130
|
}
|
|
172
131
|
if (match.status === "pending") {
|
|
132
|
+
const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
|
|
133
|
+
if (pendingMinMs && !((_c = router.getMatch(match.id)) == null ? void 0 : _c.minPendingPromise)) {
|
|
134
|
+
if (!router.isServer) {
|
|
135
|
+
const minPendingPromise = createControlledPromise();
|
|
136
|
+
Promise.resolve().then(() => {
|
|
137
|
+
router.updateMatch(match.id, (prev) => ({
|
|
138
|
+
...prev,
|
|
139
|
+
minPendingPromise
|
|
140
|
+
}));
|
|
141
|
+
});
|
|
142
|
+
setTimeout(() => {
|
|
143
|
+
minPendingPromise.resolve();
|
|
144
|
+
router.updateMatch(match.id, (prev) => ({
|
|
145
|
+
...prev,
|
|
146
|
+
minPendingPromise: void 0
|
|
147
|
+
}));
|
|
148
|
+
}, pendingMinMs);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
173
151
|
throw match.loadPromise;
|
|
174
152
|
}
|
|
175
153
|
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
package/dist/esm/Match.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Match.js","sources":["../../src/Match.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { createControlledPromise, pick } from './utils'\nimport { CatchNotFound, isNotFound } from './not-found'\nimport { isRedirect } from './redirects'\nimport { matchContext } from './matchContext'\nimport { defaultDeserializeError, isServerSideError } from './isServerSideError'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { rootRouteId } from './root'\nimport type { AnyRoute } from './route'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route: AnyRoute = router.routesById[routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n (route.options.errorComponent as any)?.preload)\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const resetKey = useRouterState({\n select: (s) => s.loadedAt,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n <MatchInner matchId={matchId} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n})\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n matchId,\n}: {\n matchId: string\n}): any {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const matchIndex = useRouterState({\n select: (s) => {\n return s.matches.findIndex((d) => d.id === matchId)\n },\n })\n\n const match = useRouterState({\n select: (s) => {\n const match = s.matches[matchIndex]!\n return pick(match, [\n 'id',\n 'status',\n 'error',\n 'loadPromise',\n 'minPendingPromise',\n ])\n },\n })\n\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n return Comp ? <Comp key={routeId} /> : <Outlet />\n }, [routeId, route.options.component, router.options.defaultComponent])\n\n React.useEffect(() => {\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n\n if (pendingMinMs && !match.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!router.isServer) {\n const minPendingPromise = createControlledPromise<void>()\n\n router.updateMatch(match.id, (prev) => ({\n ...prev,\n minPendingPromise,\n }))\n\n const id = setTimeout(() => {\n minPendingPromise.resolve()\n\n // We've handled the minPendingPromise, so we can delete it\n router.updateMatch(match.id, (prev) => ({\n ...prev,\n minPendingPromise: undefined,\n }))\n }, pendingMinMs)\n return () => clearTimeout(id)\n }\n }\n }\n return undefined\n }, [\n match.id,\n match.loadPromise,\n match.minPendingPromise,\n match.status,\n route.options.pendingMinMs,\n router,\n ])\n\n // function useChangedDiff(value: any) {\n // const ref = React.useRef(value)\n // const changed = ref.current !== value\n // if (changed) {\n // console.log(\n // 'Changed:',\n // value,\n // Object.fromEntries(\n // Object.entries(value).filter(\n // ([key, val]) => val !== ref.current[key],\n // ),\n // ),\n // )\n // }\n // ref.current = value\n // }\n\n // useChangedDiff(match)\n\n const RouteErrorComponent =\n (route.options.errorComponent ?? router.options.defaultErrorComponent) ||\n ErrorComponent\n\n if (match.status === 'notFound') {\n let error: unknown\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n\n error = deserializeError(match.error.data)\n } else {\n error = match.error\n }\n\n invariant(isNotFound(error), 'Expected a notFound error')\n\n return renderRouteNotFound(router, route, error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n throw match.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (router.isServer) {\n return (\n <RouteErrorComponent\n error={match.error}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n throw match.loadPromise\n }\n\n return (\n <>\n {out}\n {router.AfterEachMatch ? (\n <router.AfterEachMatch match={match} matchIndex={matchIndex} />\n ) : null}\n </>\n )\n})\n\nexport const Outlet = React.memo(function OutletImpl() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const { parentGlobalNotFound } = useRouterState({\n select: (s) => {\n const matches = s.matches\n const parentMatch = matches.find((d) => d.id === matchId)\n invariant(\n parentMatch,\n `Could not find parent match for matchId \"${matchId}\"`,\n )\n return {\n parentGlobalNotFound: parentMatch.globalNotFound,\n }\n },\n })\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = s.matches\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (matchId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"names":["match"],"mappings":";;;;;;;;;;;;;;;;AAkBO;AAA4C;AAEnD;;AAGE;AACA;AAA+B;;AACd;AAAyC;AAAA;AAG1D;AAAA;AACE;AAC8C;AAG1C;AAEN;AAGA;AAEA;AAGA;AAEA;AAAqC;AAAA;AAGK;AAGpC;AAAA;AAAA;AAOA;AAEA;AAIA;AAIN;AAAgC;AACb;AAIjB;AAEI;AAAC;AAAA;AACoB;AACoB;AAGjC;AACI;AACR;AAAsB;AACxB;AAEA;AAAC;AAAA;AAKK;AAIM;AAED;AAAwD;AACjE;AAE8B;AAAA;AAChC;AAAA;AAKV;AAEO;AAAsD;AAE7D;;AAGE;AACA;AAA+B;;AACd;AAAyC;AAAA;AAGpD;AAEN;AAAkC;AAE9B;AAAkD;AACpD;AAGF;AAA6B;AAEnBA;AACN;AAAmB;AACjB;AACA;AACA;AACA;AACA;AACD;AACH;AAGI;AACJ;AACA;AAA+C;AAGjD;AACM;AAEF;AAGI;AAEE;AACF;AAEA;AAAwC;AACnC;AACH;AAGI;AACJ;AAGA;AAAwC;AACnC;AACgB;AACnB;AAEG;AAAqB;AAC9B;AACF;AAEK;AAAA;AACN;AACK;AACA;AACA;AACA;AACQ;AACd;AAsBF;AAII;AACE;AACA;AACF;AAGQ;AAAiC;AAEzC;AAAc;AAGN;AAEH;AAAwC;AAG7C;AAGF;AAMA;AAAY;AAGV;AAMF;AAEI;AAAA;AAAC;AAAA;AACc;AACP;AACY;AAClB;AAAA;AAAA;AAKF;AACF;AAEM;AAAiC;AAEvC;AAAY;AACd;AAGE;AACF;AAAY;AAGd;AAEK;AAAA;AAGG;AAGV;AAEO;AACL;AACM;AACN;AAA+B;;AACd;AAAyC;AAAA;AAGpD;AAEA;AAA0C;AAE5C;AACA;AACA;AAAA;AACE;AACmD;AAE9C;AAAA;AAC6B;AAAA;AAEtC;AAGF;AAAoC;;AAEhC;AACA;AACO;AAAoB;AAC7B;AAGF;AACS;AAA4C;AAGrD;AACS;AAAA;AAGT;AAEM;AAIN;AACE;AACuD;AAIlD;AACT;;;;;;"}
|
|
1
|
+
{"version":3,"file":"Match.js","sources":["../../src/Match.tsx"],"sourcesContent":["'use client'\n\nimport * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { createControlledPromise, pick } from './utils'\nimport { CatchNotFound, isNotFound } from './not-found'\nimport { isRedirect } from './redirects'\nimport { matchContext } from './matchContext'\nimport { defaultDeserializeError, isServerSideError } from './isServerSideError'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { rootRouteId } from './root'\nimport type { AnyRoute } from './route'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n invariant(\n routeId,\n `Could not find routeId for matchId \"${matchId}\". Please file an issue!`,\n )\n\n const route: AnyRoute = router.routesById[routeId]\n\n const PendingComponent =\n route.options.pendingComponent ?? router.options.defaultPendingComponent\n\n const pendingElement = PendingComponent ? <PendingComponent /> : null\n\n const routeErrorComponent =\n route.options.errorComponent ?? router.options.defaultErrorComponent\n\n const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch\n\n const routeNotFoundComponent = route.isRoot\n ? // If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component\n (route.options.notFoundComponent ??\n router.options.notFoundRoute?.options.component)\n : route.options.notFoundComponent\n\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n (route.options.errorComponent as any)?.preload)\n ? React.Suspense\n : SafeFragment\n\n const ResolvedCatchBoundary = routeErrorComponent\n ? CatchBoundary\n : SafeFragment\n\n const ResolvedNotFoundBoundary = routeNotFoundComponent\n ? CatchNotFound\n : SafeFragment\n\n const resetKey = useRouterState({\n select: (s) => s.loadedAt,\n })\n\n return (\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => resetKey}\n errorComponent={routeErrorComponent || ErrorComponent}\n onCatch={(error, errorInfo) => {\n // Forward not found errors (we don't want to show the error component for these)\n if (isNotFound(error)) throw error\n warning(false, `Error in route match: ${matchId}`)\n routeOnCatch?.(error, errorInfo)\n }}\n >\n <ResolvedNotFoundBoundary\n fallback={(error) => {\n // If the current not found handler doesn't exist or it has a\n // route ID which doesn't match the current route, rethrow the error\n if (\n !routeNotFoundComponent ||\n (error.routeId && error.routeId !== routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n <MatchInner matchId={matchId} />\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n )\n})\n\nexport const MatchInner = React.memo(function MatchInnerImpl({\n matchId,\n}: {\n matchId: string\n}): any {\n const router = useRouter()\n\n const { match, matchIndex, routeId } = useRouterState({\n select: (s) => {\n const matchIndex = s.matches.findIndex((d) => d.id === matchId)\n const match = s.matches[matchIndex]!\n const routeId = match.routeId as string\n return {\n routeId,\n matchIndex,\n match: pick(match, ['id', 'status', 'error', 'loadPromise']),\n }\n },\n })\n\n const route = router.routesById[routeId]!\n\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n return Comp ? <Comp key={routeId} /> : <Outlet />\n }, [routeId, route.options.component, router.options.defaultComponent])\n\n // function useChangedDiff(value: any) {\n // const ref = React.useRef(value)\n // const changed = ref.current !== value\n // if (changed) {\n // console.log(\n // 'Changed:',\n // value,\n // Object.fromEntries(\n // Object.entries(value).filter(\n // ([key, val]) => val !== ref.current[key],\n // ),\n // ),\n // )\n // }\n // ref.current = value\n // }\n\n // useChangedDiff(match)\n\n const RouteErrorComponent =\n (route.options.errorComponent ?? router.options.defaultErrorComponent) ||\n ErrorComponent\n\n if (match.status === 'notFound') {\n let error: unknown\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n\n error = deserializeError(match.error.data)\n } else {\n error = match.error\n }\n\n invariant(isNotFound(error), 'Expected a notFound error')\n\n return renderRouteNotFound(router, route, error)\n }\n\n if (match.status === 'redirected') {\n // Redirects should be handled by the router transition. If we happen to\n // encounter a redirect here, it's a bug. Let's warn, but render nothing.\n invariant(isRedirect(match.error), 'Expected a redirect error')\n\n // warning(\n // false,\n // 'Tried to render a redirected route match! This is a weird circumstance, please file an issue!',\n // )\n throw match.loadPromise\n }\n\n if (match.status === 'error') {\n // If we're on the server, we need to use React's new and super\n // wonky api for throwing errors from a server side render inside\n // of a suspense boundary. This is the only way to get\n // renderToPipeableStream to not hang indefinitely.\n // We'll serialize the error and rethrow it on the client.\n if (router.isServer) {\n return (\n <RouteErrorComponent\n error={match.error}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n if (isServerSideError(match.error)) {\n const deserializeError =\n router.options.errorSerializer?.deserialize ?? defaultDeserializeError\n throw deserializeError(match.error.data)\n } else {\n throw match.error\n }\n }\n\n if (match.status === 'pending') {\n // We're pending, and if we have a minPendingMs, we need to wait for it\n const pendingMinMs =\n route.options.pendingMinMs ?? router.options.defaultPendingMinMs\n\n if (pendingMinMs && !router.getMatch(match.id)?.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!router.isServer) {\n const minPendingPromise = createControlledPromise<void>()\n\n Promise.resolve().then(() => {\n router.updateMatch(match.id, (prev) => ({\n ...prev,\n minPendingPromise,\n }))\n })\n\n setTimeout(() => {\n minPendingPromise.resolve()\n\n // We've handled the minPendingPromise, so we can delete it\n router.updateMatch(match.id, (prev) => ({\n ...prev,\n minPendingPromise: undefined,\n }))\n }, pendingMinMs)\n }\n }\n throw match.loadPromise\n }\n\n return (\n <>\n {out}\n {router.AfterEachMatch ? (\n <router.AfterEachMatch match={match} matchIndex={matchIndex} />\n ) : null}\n </>\n )\n})\n\nexport const Outlet = React.memo(function OutletImpl() {\n const router = useRouter()\n const matchId = React.useContext(matchContext)\n const routeId = useRouterState({\n select: (s) => s.matches.find((d) => d.id === matchId)?.routeId as string,\n })\n\n const route = router.routesById[routeId]!\n\n const { parentGlobalNotFound } = useRouterState({\n select: (s) => {\n const matches = s.matches\n const parentMatch = matches.find((d) => d.id === matchId)\n invariant(\n parentMatch,\n `Could not find parent match for matchId \"${matchId}\"`,\n )\n return {\n parentGlobalNotFound: parentMatch.globalNotFound,\n }\n },\n })\n\n const childMatchId = useRouterState({\n select: (s) => {\n const matches = s.matches\n const index = matches.findIndex((d) => d.id === matchId)\n return matches[index + 1]?.id\n },\n })\n\n if (parentGlobalNotFound) {\n return renderRouteNotFound(router, route, undefined)\n }\n\n if (!childMatchId) {\n return null\n }\n\n const nextMatch = <Match matchId={childMatchId} />\n\n const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\n\n if (matchId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"names":["matchIndex","match","routeId"],"mappings":";;;;;;;;;;;;;;;;AAkBO;AAA4C;AAEnD;;AAGE;AACA;AAA+B;;AACd;AAAyC;AAAA;AAG1D;AAAA;AACE;AAC8C;AAG1C;AAEN;AAGA;AAEA;AAGA;AAEA;AAAqC;AAAA;AAGK;AAGpC;AAAA;AAAA;AAOA;AAEA;AAIA;AAIN;AAAgC;AACb;AAIjB;AAEI;AAAC;AAAA;AACoB;AACoB;AAGjC;AACI;AACR;AAAsB;AACxB;AAEA;AAAC;AAAA;AAKK;AAIM;AAED;AAAwD;AACjE;AAE8B;AAAA;AAChC;AAAA;AAKV;AAEO;AAAsD;AAE7D;;AAGE;AAEA;AAAsD;AAE5CA;AACAC;AACN;AACO;AAAA;AACLC;AACAF;AAC2D;AAAA;AAE/D;AAGI;AAEA;AACJ;AACA;AAA+C;AAsBjD;AAII;AACE;AACA;AACF;AAGQ;AAAiC;AAEzC;AAAc;AAGN;AAEH;AAAwC;AAG7C;AAGF;AAMA;AAAY;AAGV;AAMF;AAEI;AAAA;AAAC;AAAA;AACc;AACP;AACY;AAClB;AAAA;AAAA;AAKF;AACF;AAEM;AAAiC;AAEvC;AAAY;AACd;AAGE;AAEF;AAGA;AAEM;AACF;AAEQ;AACN;AAAwC;AACnC;AACH;AACA;AAGJ;AACE;AAGA;AAAwC;AACnC;AACgB;AACnB;AACW;AACjB;AAEF;AAAY;AAGd;AAEK;AAAA;AAGG;AAGV;AAEO;AACL;AACM;AACN;AAA+B;;AACd;AAAyC;AAAA;AAGpD;AAEA;AAA0C;AAE5C;AACA;AACA;AAAA;AACE;AACmD;AAE9C;AAAA;AAC6B;AAAA;AAEtC;AAGF;AAAoC;;AAEhC;AACA;AACO;AAAoB;AAC7B;AAGF;AACS;AAA4C;AAGrD;AACS;AAAA;AAGT;AAEM;AAIN;AACE;AACuD;AAIlD;AACT;;;;;;"}
|
package/dist/esm/fileRoute.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { NoInfer } from '@tanstack/react-store';
|
|
2
2
|
import { ParsePathParams } from './link.js';
|
|
3
|
-
import { AnyContext, AnyPathParams, AnyRoute,
|
|
3
|
+
import { AnyContext, AnyPathParams, AnyRoute, AnySearchValidator, DefaultSearchValidator, FileBaseRouteOptions, InferAllContext, ResolveAllContext, ResolveAllParamsFromParent, ResolveLoaderData, ResolveRouteContext, Route, RouteConstraints, RouteContext, RouteLoaderFn, UpdatableRouteOptions } from './route.js';
|
|
4
4
|
import { MakeRouteMatch } from './Matches.js';
|
|
5
5
|
import { RegisteredRouter } from './router.js';
|
|
6
6
|
import { RouteById, RouteIds } from './routeInfo.js';
|
|
@@ -18,7 +18,7 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
|
|
|
18
18
|
constructor(path: TFilePath, _opts?: {
|
|
19
19
|
silent: boolean;
|
|
20
20
|
});
|
|
21
|
-
createRoute: <
|
|
21
|
+
createRoute: <TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TParams = Record<ParsePathParams<TPath>, string>, TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown>(options?: FileBaseRouteOptions<TParentRoute, TPath, TSearchValidator, TParams, TAllParams, TRouteContextReturn, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn> & UpdatableRouteOptions<TParentRoute, TId, TAllParams, TSearchValidator, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>) => Route<TParentRoute, TPath, TFullPath, TFilePath, TId, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren>;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
@deprecated It's recommended not to split loaders into separate files.
|
|
@@ -26,7 +26,7 @@ export declare class FileRoute<TFilePath extends keyof FileRoutesByPath, TParent
|
|
|
26
26
|
`createFileRoute('/path/to/file)(options)` options.
|
|
27
27
|
*/
|
|
28
28
|
export declare function FileRouteLoader<TFilePath extends keyof FileRoutesByPath, TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute']>(_path: TFilePath): <TLoaderData>(loaderFn: RouteLoaderFn<TRoute['types']['allParams'], TRoute['types']['loaderDeps'], TRoute['types']['allContext'], TLoaderData>) => RouteLoaderFn<TRoute['types']['allParams'], TRoute['types']['loaderDeps'], TRoute['types']['allContext'], NoInfer<TLoaderData>>;
|
|
29
|
-
export type LazyRouteOptions = Pick<UpdatableRouteOptions<string, AnyPathParams,
|
|
29
|
+
export type LazyRouteOptions = Pick<UpdatableRouteOptions<AnyRoute, string, AnyPathParams, AnySearchValidator, {}, AnyContext, AnyContext, {}>, 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'>;
|
|
30
30
|
export declare class LazyRoute<TRoute extends AnyRoute> {
|
|
31
31
|
options: {
|
|
32
32
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport type { NoInfer } from '@tanstack/react-store'\nimport type { ParsePathParams } from './link'\nimport type {\n AnyContext,\n AnyPathParams,\n AnyRoute,\n
|
|
1
|
+
{"version":3,"file":"fileRoute.js","sources":["../../src/fileRoute.ts"],"sourcesContent":["import warning from 'tiny-warning'\nimport { createRoute } from './route'\nimport { useMatch } from './useMatch'\nimport { useLoaderDeps } from './useLoaderDeps'\nimport { useLoaderData } from './useLoaderData'\nimport { useSearch } from './useSearch'\nimport { useParams } from './useParams'\nimport { useNavigate } from './useNavigate'\nimport type { NoInfer } from '@tanstack/react-store'\nimport type { ParsePathParams } from './link'\nimport type {\n AnyContext,\n AnyPathParams,\n AnyRoute,\n AnySearchValidator,\n DefaultSearchValidator,\n FileBaseRouteOptions,\n InferAllContext,\n ResolveAllContext,\n ResolveAllParamsFromParent,\n ResolveLoaderData,\n ResolveRouteContext,\n Route,\n RouteConstraints,\n RouteContext,\n RouteLoaderFn,\n UpdatableRouteOptions,\n} from './route'\nimport type { MakeRouteMatch } from './Matches'\nimport type { RegisteredRouter } from './router'\nimport type { RouteById, RouteIds } from './routeInfo'\n\nexport interface FileRoutesByPath {\n // '/': {\n // parentRoute: typeof rootRoute\n // }\n}\n\nexport function createFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n>(\n path: TFilePath,\n): FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>['createRoute'] {\n return new FileRoute<TFilePath, TParentRoute, TId, TPath, TFullPath>(path, {\n silent: true,\n }).createRoute\n}\n\n/** \n @deprecated It's no longer recommended to use the `FileRoute` class directly.\n Instead, use `createFileRoute('/path/to/file')(options)` to create a file route.\n*/\nexport class FileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TParentRoute extends AnyRoute = FileRoutesByPath[TFilePath]['parentRoute'],\n TId extends RouteConstraints['TId'] = FileRoutesByPath[TFilePath]['id'],\n TPath extends RouteConstraints['TPath'] = FileRoutesByPath[TFilePath]['path'],\n TFullPath extends\n RouteConstraints['TFullPath'] = FileRoutesByPath[TFilePath]['fullPath'],\n> {\n silent?: boolean\n\n constructor(\n public path: TFilePath,\n _opts?: { silent: boolean },\n ) {\n this.silent = _opts?.silent\n }\n\n createRoute = <\n TSearchValidator extends AnySearchValidator = DefaultSearchValidator,\n TParams = Record<ParsePathParams<TPath>, string>,\n TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>,\n TRouteContextReturn = RouteContext,\n TRouteContext = ResolveRouteContext<TRouteContextReturn>,\n TAllContext = ResolveAllContext<TParentRoute, TRouteContext>,\n TLoaderDeps extends Record<string, any> = {},\n TLoaderDataReturn = {},\n TLoaderData = ResolveLoaderData<TLoaderDataReturn>,\n TChildren = unknown,\n >(\n options?: FileBaseRouteOptions<\n TParentRoute,\n TPath,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n InferAllContext<TParentRoute>,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn\n > &\n UpdatableRouteOptions<\n TParentRoute,\n TId,\n TAllParams,\n TSearchValidator,\n TLoaderData,\n TAllContext,\n TRouteContext,\n TLoaderDeps\n >,\n ): Route<\n TParentRoute,\n TPath,\n TFullPath,\n TFilePath,\n TId,\n TSearchValidator,\n TParams,\n TAllParams,\n TRouteContextReturn,\n TRouteContext,\n TAllContext,\n TLoaderDeps,\n TLoaderDataReturn,\n TLoaderData,\n TChildren\n > => {\n warning(\n this.silent,\n 'FileRoute is deprecated and will be removed in the next major version. Use the createFileRoute(path)(options) function instead.',\n )\n const route = createRoute(options as any)\n ;(route as any).isRoot = false\n return route as any\n }\n}\n\n/** \n @deprecated It's recommended not to split loaders into separate files.\n Instead, place the loader function in the the main route file, inside the\n `createFileRoute('/path/to/file)(options)` options.\n*/\nexport function FileRouteLoader<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(\n _path: TFilePath,\n): <TLoaderData>(\n loaderFn: RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n TLoaderData\n >,\n) => RouteLoaderFn<\n TRoute['types']['allParams'],\n TRoute['types']['loaderDeps'],\n TRoute['types']['allContext'],\n NoInfer<TLoaderData>\n> {\n warning(\n false,\n `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`,\n )\n return (loaderFn) => loaderFn\n}\n\nexport type LazyRouteOptions = Pick<\n UpdatableRouteOptions<\n AnyRoute,\n string,\n AnyPathParams,\n AnySearchValidator,\n {},\n AnyContext,\n AnyContext,\n {}\n >,\n 'component' | 'errorComponent' | 'pendingComponent' | 'notFoundComponent'\n>\n\nexport class LazyRoute<TRoute extends AnyRoute> {\n options: {\n id: string\n } & LazyRouteOptions\n\n constructor(\n opts: {\n id: string\n } & LazyRouteOptions,\n ) {\n this.options = opts\n ;(this as any).$$typeof = Symbol.for('react.memo')\n }\n\n useMatch = <\n TRouteMatch = MakeRouteMatch<\n RegisteredRouter['routeTree'],\n TRoute['types']['id']\n >,\n TSelected = TRouteMatch,\n >(opts?: {\n select?: (match: TRouteMatch) => TSelected\n }): TSelected => {\n return useMatch({ select: opts?.select, from: this.options.id })\n }\n\n useRouteContext = <TSelected = TRoute['types']['allContext']>(opts?: {\n select?: (s: TRoute['types']['allContext']) => TSelected\n }): TSelected => {\n return useMatch({\n from: this.options.id,\n select: (d: any) => (opts?.select ? opts.select(d.context) : d.context),\n })\n }\n\n useSearch = <TSelected = TRoute['types']['fullSearchSchema']>(opts?: {\n select?: (s: TRoute['types']['fullSearchSchema']) => TSelected\n }): TSelected => {\n return useSearch({ ...opts, from: this.options.id })\n }\n\n useParams = <TSelected = TRoute['types']['allParams']>(opts?: {\n select?: (s: TRoute['types']['allParams']) => TSelected\n }): TSelected => {\n return useParams({ ...opts, from: this.options.id })\n }\n\n useLoaderDeps = <TSelected = TRoute['types']['loaderDeps']>(opts?: {\n select?: (s: TRoute['types']['loaderDeps']) => TSelected\n }): TSelected => {\n return useLoaderDeps({ ...opts, from: this.options.id } as any)\n }\n\n useLoaderData = <TSelected = TRoute['types']['loaderData']>(opts?: {\n select?: (s: TRoute['types']['loaderData']) => TSelected\n }): TSelected => {\n return useLoaderData({ ...opts, from: this.options.id } as any)\n }\n\n useNavigate = () => {\n return useNavigate({ from: this.options.id })\n }\n}\n\nexport function createLazyRoute<\n TId extends RouteIds<RegisteredRouter['routeTree']>,\n TRoute extends AnyRoute = RouteById<RegisteredRouter['routeTree'], TId>,\n>(id: TId) {\n return (opts: LazyRouteOptions) => {\n return new LazyRoute<TRoute>({ id: id as any, ...opts })\n }\n}\n\nexport function createLazyFileRoute<\n TFilePath extends keyof FileRoutesByPath,\n TRoute extends FileRoutesByPath[TFilePath]['preLoaderRoute'],\n>(id: TFilePath) {\n return (opts: LazyRouteOptions) => new LazyRoute<TRoute>({ id, ...opts })\n}\n"],"names":["opts"],"mappings":";;;;;;;;AAsCO,SAAS,gBAQd,MAC0E;AACnE,SAAA,IAAI,UAA0D,MAAM;AAAA,IACzE,QAAQ;AAAA,EACT,CAAA,EAAE;AACL;AAMO,MAAM,UAOX;AAAA,EAGA,YACS,MACP,OACA;AAFO,SAAA,OAAA;AAMT,SAAA,cAAc,CAYZ,YAsCG;AACH;AAAA,QACE,KAAK;AAAA,QACL;AAAA,MAAA;AAEI,YAAA,QAAQ,YAAY,OAAc;AACtC,YAAc,SAAS;AAClB,aAAA;AAAA,IAAA;AA5DP,SAAK,SAAS,+BAAO;AAAA,EACvB;AA6DF;AAOO,SAAS,gBAId,OAaA;AACA;AAAA,IACE;AAAA,IACA;AAAA,EAAA;AAEF,SAAO,CAAC,aAAa;AACvB;AAgBO,MAAM,UAAmC;AAAA,EAK9C,YACE,MAGA;AAKF,SAAA,WAAW,CAMTA,UAEe;AACR,aAAA,SAAS,EAAE,QAAQA,SAAA,gBAAAA,MAAM,QAAQ,MAAM,KAAK,QAAQ,GAAA,CAAI;AAAA,IAAA;AAGjE,SAAA,kBAAkB,CAA4CA,UAE7C;AACf,aAAO,SAAS;AAAA,QACd,MAAM,KAAK,QAAQ;AAAA,QACnB,QAAQ,CAAC,OAAYA,SAAA,gBAAAA,MAAM,UAASA,MAAK,OAAO,EAAE,OAAO,IAAI,EAAE;AAAA,MAAA,CAChE;AAAA,IAAA;AAGH,SAAA,YAAY,CAAkDA,UAE7C;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,YAAY,CAA2CA,UAEtC;AACR,aAAA,UAAU,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAGrD,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAGhE,SAAA,gBAAgB,CAA4CA,UAE3C;AACR,aAAA,cAAc,EAAE,GAAGA,OAAM,MAAM,KAAK,QAAQ,IAAW;AAAA,IAAA;AAGhE,SAAA,cAAc,MAAM;AAClB,aAAO,YAAY,EAAE,MAAM,KAAK,QAAQ,IAAI;AAAA,IAAA;AAlD5C,SAAK,UAAU;AACb,SAAa,WAAW,OAAO,IAAI,YAAY;AAAA,EACnD;AAkDF;AAEO,SAAS,gBAGd,IAAS;AACT,SAAO,CAAC,SAA2B;AACjC,WAAO,IAAI,UAAkB,EAAE,IAAe,GAAG,KAAM,CAAA;AAAA,EAAA;AAE3D;AAEO,SAAS,oBAGd,IAAe;AACR,SAAA,CAAC,SAA2B,IAAI,UAAkB,EAAE,IAAI,GAAG,MAAM;AAC1E;"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ export type { AnyRedirect, Redirect, ResolvedRedirect } from './redirects.js';
|
|
|
31
31
|
export { rootRouteId } from './root.js';
|
|
32
32
|
export type { RootRouteId } from './root.js';
|
|
33
33
|
export { RouteApi, getRouteApi, Route, createRoute, RootRoute, rootRouteWithContext, createRootRoute, createRootRouteWithContext, createRouteMask, NotFoundRoute, } from './route.js';
|
|
34
|
-
export type { AnyPathParams, SearchSchemaInput, AnySearchSchema, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn,
|
|
34
|
+
export type { AnyPathParams, SearchSchemaInput, SearchValidatorAdapter, AnySearchSchema, AnyContext, RouteContext, PreloadableObj, RoutePathOptions, StaticDataRouteOption, RoutePathOptionsIntersection, RouteOptions, FileBaseRouteOptions, BaseRouteOptions, UpdatableRouteOptions, UpdatableStaticRouteOption, MetaDescriptor, RouteLinkEntry, ParseParamsFn, RouteLoaderFn, LoaderFnContext, SearchFilter, ResolveId, InferFullSearchSchema, InferFullSearchSchemaInput, ResolveFullSearchSchema, ResolveFullSearchSchemaInput, AnyRoute, RouteConstraints, AnyRootRoute, ResolveFullPath, RouteMask, ErrorRouteProps, ErrorComponentProps, NotFoundRouteProps, ReactNode, SyncRouteComponent, AsyncRouteComponent, RouteComponent, ErrorRouteComponent, NotFoundRouteComponent, TrimPath, TrimPathLeft, TrimPathRight, RootRouteOptions, AnyRouteWithContext, } from './route.js';
|
|
35
35
|
export type { ParseRoute, RoutesById, RouteById, RouteIds, RoutesByPath, RouteByPath, RoutePaths, FullSearchSchema, AllParams, } from './routeInfo.js';
|
|
36
36
|
export { componentTypes, createRouter, Router, lazyFn, SearchParamError, PathParamError, getInitialRouterState, defaultSerializeError, } from './router.js';
|
|
37
37
|
export type { Register, AnyRouter, RegisteredRouter, HydrationCtx, RouterContextOptions, TrailingSlashOption, RouterOptions, RouterTransformer, RouterErrorSerializer, RouterState, ListenerFn, BuildNextOptions, DehydratedRouterState, DehydratedRouteMatch, DehydratedRouter, RouterConstructorOptions, RouterEvents, RouterEvent, RouterListener, AnyRouterWithContext, } from './router.js';
|
package/dist/esm/route.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export type RoutePathOptionsIntersection<TCustomId, TPath> = {
|
|
|
32
32
|
path: TPath;
|
|
33
33
|
id: TCustomId;
|
|
34
34
|
};
|
|
35
|
-
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string,
|
|
35
|
+
export type RouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TParams = AnyPathParams, TAllParams = TParams, TRouteContextReturn = RouteContext, TRouteContext = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>> = BaseRouteOptions<TParentRoute, TCustomId, TPath, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TParentAllContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & UpdatableRouteOptions<NoInfer<TParentRoute>, NoInfer<TCustomId>, NoInfer<TAllParams>, NoInfer<TSearchValidator>, NoInfer<TLoaderData>, NoInfer<TAllContext>, NoInfer<TRouteContext>, NoInfer<TLoaderDeps>>;
|
|
36
36
|
export type ParseParamsFn<TPath extends string, TParams> = (rawParams: Record<ParsePathParams<TPath>, string>) => TParams extends Record<ParsePathParams<TPath>, any> ? TParams : Record<ParsePathParams<TPath>, any>;
|
|
37
37
|
export type StringifyParamsFn<TPath extends string, TParams> = (params: TParams) => Record<ParsePathParams<TPath>, string>;
|
|
38
38
|
export type ParamsOptions<TPath extends string, TParams> = {
|
|
@@ -52,16 +52,14 @@ export type ParamsOptions<TPath extends string, TParams> = {
|
|
|
52
52
|
export interface FullSearchSchemaOption<TFullSearchSchema> {
|
|
53
53
|
search: TFullSearchSchema;
|
|
54
54
|
}
|
|
55
|
-
export type FileBaseRouteOptions<
|
|
56
|
-
validateSearch?:
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
beforeLoad?: (ctx: BeforeLoadContext<TFullSearchSchema, TAllParams, TParentAllContext>) => Promise<TRouteContextReturn> | TRouteContextReturn | void;
|
|
61
|
-
loaderDeps?: (opts: FullSearchSchemaOption<TFullSearchSchema>) => TLoaderDeps;
|
|
55
|
+
export type FileBaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TPath extends string = string, TSearchValidator extends AnySearchValidator = undefined, TParams = {}, TAllParams = {}, TRouteContextReturn = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}> = {
|
|
56
|
+
validateSearch?: TSearchValidator;
|
|
57
|
+
shouldReload?: boolean | ((match: LoaderFnContext<TAllParams, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TAllContext>) => any);
|
|
58
|
+
beforeLoad?: (ctx: BeforeLoadContext<ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TAllParams, TParentAllContext>) => Promise<TRouteContextReturn> | TRouteContextReturn | void;
|
|
59
|
+
loaderDeps?: (opts: FullSearchSchemaOption<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>) => TLoaderDeps;
|
|
62
60
|
loader?: (ctx: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>) => TLoaderDataReturn | Promise<TLoaderDataReturn>;
|
|
63
61
|
} & ParamsOptions<TPath, TParams>;
|
|
64
|
-
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string,
|
|
62
|
+
export type BaseRouteOptions<TParentRoute extends AnyRoute = AnyRoute, TCustomId extends string = string, TPath extends string = string, TSearchValidator extends AnySearchValidator = undefined, TParams = {}, TAllParams = {}, TRouteContextReturn = RouteContext, TParentAllContext = AnyContext, TAllContext = AnyContext, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}> = RoutePathOptions<TCustomId, TPath> & FileBaseRouteOptions<TParentRoute, TPath, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TParentAllContext, TAllContext, TLoaderDeps, TLoaderDataReturn> & {
|
|
65
63
|
getParentRoute: () => TParentRoute;
|
|
66
64
|
};
|
|
67
65
|
export interface BeforeLoadContext<TFullSearchSchema, TAllParams, TParentAllContext> extends FullSearchSchemaOption<TFullSearchSchema> {
|
|
@@ -77,7 +75,7 @@ export interface BeforeLoadContext<TFullSearchSchema, TAllParams, TParentAllCont
|
|
|
77
75
|
buildLocation: BuildLocationFn;
|
|
78
76
|
cause: 'preload' | 'enter' | 'stay';
|
|
79
77
|
}
|
|
80
|
-
export type UpdatableRouteOptions<
|
|
78
|
+
export type UpdatableRouteOptions<TParentRoute extends AnyRoute, TRouteId, TAllParams, TSearchValidator extends AnySearchValidator, TLoaderData, TAllContext, TRouteContext, TLoaderDeps> = {
|
|
81
79
|
caseSensitive?: boolean;
|
|
82
80
|
wrapInSuspense?: boolean;
|
|
83
81
|
component?: RouteComponent;
|
|
@@ -90,16 +88,16 @@ export type UpdatableRouteOptions<TRouteId, TAllParams, TFullSearchSchema, TLoad
|
|
|
90
88
|
gcTime?: number;
|
|
91
89
|
preloadStaleTime?: number;
|
|
92
90
|
preloadGcTime?: number;
|
|
93
|
-
preSearchFilters?: Array<SearchFilter<
|
|
94
|
-
postSearchFilters?: Array<SearchFilter<
|
|
91
|
+
preSearchFilters?: Array<SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>>;
|
|
92
|
+
postSearchFilters?: Array<SearchFilter<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>>;
|
|
95
93
|
onCatch?: (error: Error, errorInfo: React.ErrorInfo) => void;
|
|
96
94
|
onError?: (err: any) => void;
|
|
97
|
-
onEnter?: (match:
|
|
98
|
-
onStay?: (match:
|
|
99
|
-
onLeave?: (match:
|
|
95
|
+
onEnter?: (match: RouteMatch<TRouteId, TAllParams, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>) => void;
|
|
96
|
+
onStay?: (match: RouteMatch<TRouteId, TAllParams, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>) => void;
|
|
97
|
+
onLeave?: (match: RouteMatch<TRouteId, TAllParams, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>) => void;
|
|
100
98
|
meta?: (ctx: {
|
|
101
|
-
matches: Array<
|
|
102
|
-
match:
|
|
99
|
+
matches: Array<RouteMatch<TRouteId, TAllParams, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>>;
|
|
100
|
+
match: RouteMatch<TRouteId, TAllParams, ResolveFullSearchSchema<TParentRoute, TSearchValidator>, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>;
|
|
103
101
|
params: TAllParams;
|
|
104
102
|
loaderData: TLoaderData;
|
|
105
103
|
}) => Array<React.JSX.IntrinsicElements['meta']>;
|
|
@@ -142,11 +140,23 @@ type LdJsonArray = Array<LdJsonValue> | ReadonlyArray<LdJsonValue>;
|
|
|
142
140
|
type LdJsonPrimitive = string | number | boolean | null;
|
|
143
141
|
type LdJsonValue = LdJsonPrimitive | LdJsonObject | LdJsonArray;
|
|
144
142
|
export type RouteLinkEntry = {};
|
|
145
|
-
export
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
export
|
|
143
|
+
export interface SearchValidatorObj<TInput, TOutput> {
|
|
144
|
+
parse: SearchValidatorFn<TInput, TOutput>;
|
|
145
|
+
}
|
|
146
|
+
export type AnySearchValidatorObj = SearchValidatorObj<any, any>;
|
|
147
|
+
export interface SearchValidatorAdapter<TInput, TOutput> {
|
|
148
|
+
types: {
|
|
149
|
+
input: TInput;
|
|
150
|
+
output: TOutput;
|
|
151
|
+
};
|
|
152
|
+
parse: (input: unknown) => TOutput;
|
|
153
|
+
}
|
|
154
|
+
export type AnySearchValidatorAdapter = SearchValidatorAdapter<any, any>;
|
|
155
|
+
export type AnySearchValidatorFn = SearchValidatorFn<any, any>;
|
|
156
|
+
export type SearchValidatorFn<TInput, TOutput> = (input: TInput) => TOutput;
|
|
157
|
+
export type SearchValidator<TInput, TOutput> = SearchValidatorObj<TInput, TOutput> | SearchValidatorFn<TInput, TOutput> | SearchValidatorAdapter<TInput, TOutput> | undefined;
|
|
158
|
+
export type AnySearchValidator = SearchValidator<any, any>;
|
|
159
|
+
export type DefaultSearchValidator = SearchValidator<Record<string, unknown>, AnySearchSchema>;
|
|
150
160
|
export type RouteLoaderFn<in out TAllParams = {}, in out TLoaderDeps extends Record<string, any> = {}, in out TAllContext = AnyContext, TLoaderData = undefined> = (match: LoaderFnContext<TAllParams, TLoaderDeps, TAllContext>) => TLoaderData | Promise<TLoaderData>;
|
|
151
161
|
export interface LoaderFnContext<in out TAllParams = {}, in out TLoaderDeps = {}, in out TAllContext = AnyContext> {
|
|
152
162
|
abortController: AbortController;
|
|
@@ -187,9 +197,12 @@ export type InferAllContext<TRoute> = TRoute extends {
|
|
|
187
197
|
allContext: infer TAllContext;
|
|
188
198
|
};
|
|
189
199
|
} ? TAllContext : {};
|
|
190
|
-
export type
|
|
191
|
-
export type
|
|
192
|
-
export type
|
|
200
|
+
export type ResolveSearchSchemaFnInput<TSearchValidator extends AnySearchValidator> = TSearchValidator extends (input: infer TSearchSchemaInput) => any ? TSearchSchemaInput extends SearchSchemaInput ? Omit<TSearchSchemaInput, keyof SearchSchemaInput> : ResolveSearchSchemaFn<TSearchValidator> : AnySearchSchema;
|
|
201
|
+
export type ResolveSearchSchemaInput<TSearchValidator extends AnySearchValidator> = TSearchValidator extends AnySearchValidatorAdapter ? TSearchValidator['types']['input'] : TSearchValidator extends AnySearchValidatorObj ? ResolveSearchSchemaFnInput<TSearchValidator['parse']> : ResolveSearchSchemaFnInput<TSearchValidator>;
|
|
202
|
+
export type ResolveSearchSchemaFn<TSearchValidator extends AnySearchValidator> = TSearchValidator extends (...args: any) => infer TSearchSchema ? TSearchSchema : AnySearchSchema;
|
|
203
|
+
export type ResolveSearchSchema<TSearchValidator extends AnySearchValidator> = unknown extends TSearchValidator ? TSearchValidator : TSearchValidator extends AnySearchValidatorAdapter ? TSearchValidator['types']['output'] : TSearchValidator extends AnySearchValidatorObj ? ResolveSearchSchemaFn<TSearchValidator['parse']> : ResolveSearchSchemaFn<TSearchValidator>;
|
|
204
|
+
export type ResolveFullSearchSchema<TParentRoute extends AnyRoute, TSearchValidator extends AnySearchValidator> = unknown extends TParentRoute ? ResolveSearchSchema<TSearchValidator> : Assign<InferFullSearchSchema<TParentRoute>, ResolveSearchSchema<TSearchValidator>>;
|
|
205
|
+
export type ResolveFullSearchSchemaInput<TParentRoute extends AnyRoute, TSearchValidator extends AnySearchValidator> = Assign<InferFullSearchSchemaInput<TParentRoute>, ResolveSearchSchemaInput<TSearchValidator>>;
|
|
193
206
|
export type ResolveRouteContext<TRouteContextReturn> = [
|
|
194
207
|
TRouteContextReturn
|
|
195
208
|
] extends [never] ? RouteContext : TRouteContextReturn;
|
|
@@ -197,9 +210,9 @@ export type ResolveAllContext<TParentRoute extends AnyRoute, TRouteContext> = As
|
|
|
197
210
|
export type ResolveLoaderData<TLoaderDataReturn> = [TLoaderDataReturn] extends [
|
|
198
211
|
never
|
|
199
212
|
] ? undefined : TLoaderDataReturn;
|
|
200
|
-
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any
|
|
213
|
+
export interface AnyRoute extends Route<any, any, any, any, any, any, any, any, any, any, any, any, any, any, any> {
|
|
201
214
|
}
|
|
202
|
-
export type AnyRouteWithContext<TContext> = Route<any, any, any, any, any, any, any, any, any, any, any, any,
|
|
215
|
+
export type AnyRouteWithContext<TContext> = Route<any, any, any, any, any, any, any, any, any, any, any, any, TContext, any, any>;
|
|
203
216
|
export type ResolveAllParamsFromParent<TParentRoute extends AnyRoute, TParams> = Assign<InferAllParams<TParentRoute>, TParams>;
|
|
204
217
|
export type RouteConstraints = {
|
|
205
218
|
TParentRoute: AnyRoute;
|
|
@@ -248,9 +261,9 @@ export declare class RouteApi<TId extends RouteIds<RegisteredRouter['routeTree']
|
|
|
248
261
|
useNavigate: () => UseNavigateResult<TRoute["fullPath"]>;
|
|
249
262
|
notFound: (opts?: NotFoundError) => NotFoundError;
|
|
250
263
|
}
|
|
251
|
-
export declare class Route<in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, in out TPath extends RouteConstraints['TPath'] = '/', in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends RouteConstraints['TCustomId'] = string, in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, in out
|
|
264
|
+
export declare class Route<in out TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, in out TPath extends RouteConstraints['TPath'] = '/', in out TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, in out TCustomId extends RouteConstraints['TCustomId'] = string, in out TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator, in out TParams = Record<ParsePathParams<TPath>, string>, in out TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, in out TRouteContext = ResolveRouteContext<TRouteContextReturn>, in out TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, in out TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>, in out TChildren = unknown> {
|
|
252
265
|
isRoot: TParentRoute extends Route<any> ? true : false;
|
|
253
|
-
options: RouteOptions<TParentRoute, TCustomId, TPath,
|
|
266
|
+
options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>;
|
|
254
267
|
parentRoute: TParentRoute;
|
|
255
268
|
id: TId;
|
|
256
269
|
path: TPath;
|
|
@@ -265,7 +278,7 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
265
278
|
/**
|
|
266
279
|
* @deprecated Use the `createRoute` function instead.
|
|
267
280
|
*/
|
|
268
|
-
constructor(options?: RouteOptions<TParentRoute, TCustomId, TPath,
|
|
281
|
+
constructor(options?: RouteOptions<TParentRoute, TCustomId, TPath, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>);
|
|
269
282
|
types: {
|
|
270
283
|
parentRoute: TParentRoute;
|
|
271
284
|
path: TPath;
|
|
@@ -273,11 +286,11 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
273
286
|
fullPath: TFullPath;
|
|
274
287
|
customId: TCustomId;
|
|
275
288
|
id: TId;
|
|
276
|
-
searchSchema:
|
|
277
|
-
searchSchemaInput:
|
|
278
|
-
|
|
279
|
-
fullSearchSchema:
|
|
280
|
-
fullSearchSchemaInput:
|
|
289
|
+
searchSchema: ResolveSearchSchema<TSearchValidator>;
|
|
290
|
+
searchSchemaInput: ResolveSearchSchemaInput<TSearchValidator>;
|
|
291
|
+
searchValidator: TSearchValidator;
|
|
292
|
+
fullSearchSchema: ResolveFullSearchSchema<TParentRoute, TSearchValidator>;
|
|
293
|
+
fullSearchSchemaInput: ResolveFullSearchSchemaInput<TParentRoute, TSearchValidator>;
|
|
281
294
|
params: TParams;
|
|
282
295
|
allParams: TAllParams;
|
|
283
296
|
routeContext: TRouteContext;
|
|
@@ -289,11 +302,11 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
289
302
|
init: (opts: {
|
|
290
303
|
originalIndex: number;
|
|
291
304
|
}) => void;
|
|
292
|
-
addChildren<const TNewChildren extends Record<string, AnyRoute> | ReadonlyArray<AnyRoute>>(children: TNewChildren): Route<TParentRoute, TPath, TFullPath, TCustomId, TId,
|
|
305
|
+
addChildren<const TNewChildren extends Record<string, AnyRoute> | ReadonlyArray<AnyRoute>>(children: TNewChildren): Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TNewChildren>;
|
|
293
306
|
updateLoader: <TNewLoaderData = unknown>(options: {
|
|
294
307
|
loader: RouteLoaderFn<TAllParams, TLoaderDeps, TAllContext, TNewLoaderData>;
|
|
295
|
-
}) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId,
|
|
296
|
-
update: (options: UpdatableRouteOptions<TCustomId, TAllParams,
|
|
308
|
+
}) => Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TLoaderDeps, TNewLoaderData, TChildren>;
|
|
309
|
+
update: (options: UpdatableRouteOptions<TParentRoute, TCustomId, TAllParams, TSearchValidator, TLoaderData, TAllContext, TRouteContext, TLoaderDeps>) => this;
|
|
297
310
|
lazy: (lazyFn: () => Promise<LazyRoute<any>>) => this;
|
|
298
311
|
useMatch: <TRouter extends AnyRouter = AnyRouter, TRouteTree extends AnyRoute = TRouter["routeTree"], TRouteMatch = MakeRouteMatch<TRouteTree, TId>, TSelected = TRouteMatch>(opts?: {
|
|
299
312
|
select?: (match: TRouteMatch) => TSelected;
|
|
@@ -301,8 +314,8 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
301
314
|
useRouteContext: <TSelected = Expand<TAllContext>>(opts?: {
|
|
302
315
|
select?: (search: Expand<TAllContext>) => TSelected;
|
|
303
316
|
}) => TSelected;
|
|
304
|
-
useSearch: <TSelected = Expand<
|
|
305
|
-
select?: (search: Expand<
|
|
317
|
+
useSearch: <TSelected = Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>>(opts?: {
|
|
318
|
+
select?: (search: Expand<ResolveFullSearchSchema<TParentRoute, TSearchValidator>>) => TSelected;
|
|
306
319
|
}) => TSelected;
|
|
307
320
|
useParams: <TSelected = Expand<TAllParams>>(opts?: {
|
|
308
321
|
select?: (search: Expand<TAllParams>) => TSelected;
|
|
@@ -315,15 +328,12 @@ export declare class Route<in out TParentRoute extends RouteConstraints['TParent
|
|
|
315
328
|
}) => TSelected;
|
|
316
329
|
useNavigate: () => UseNavigateResult<TFullPath>;
|
|
317
330
|
}
|
|
318
|
-
export declare function createRoute<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>,
|
|
331
|
+
export declare function createRoute<TParentRoute extends RouteConstraints['TParentRoute'] = AnyRoute, TPath extends RouteConstraints['TPath'] = '/', TFullPath extends RouteConstraints['TFullPath'] = ResolveFullPath<TParentRoute, TPath>, TCustomId extends RouteConstraints['TCustomId'] = string, TId extends RouteConstraints['TId'] = ResolveId<TParentRoute, TCustomId, TPath>, TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TParams = Record<ParsePathParams<TPath>, string>, TAllParams = ResolveAllParamsFromParent<TParentRoute, TParams>, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown>(options: RouteOptions<TParentRoute, TCustomId, TPath, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>): Route<TParentRoute, TPath, TFullPath, TCustomId, TId, TSearchValidator, TParams, TAllParams, TRouteContextReturn, TRouteContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren>;
|
|
319
332
|
export type AnyRootRoute = RootRoute<any, any, any, any, any, any, any, any>;
|
|
320
|
-
export type RootRouteOptions<
|
|
333
|
+
export type RootRouteOptions<TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TRouterContext = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>> = Omit<RouteOptions<any, // TParentRoute
|
|
321
334
|
RootRouteId, // TCustomId
|
|
322
335
|
'', // TPath
|
|
323
|
-
|
|
324
|
-
TSearchSchema, // TSearchSchema
|
|
325
|
-
TSearchSchema, // TFullSearchSchema
|
|
326
|
-
{}, // TParams
|
|
336
|
+
TSearchValidator, {}, // TParams
|
|
327
337
|
{}, // TAllParams
|
|
328
338
|
TRouteContextReturn, // TRouteContextReturn
|
|
329
339
|
TRouteContext, // TRouteContext
|
|
@@ -331,20 +341,17 @@ TRouterContext, // TParentAllContext
|
|
|
331
341
|
Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
332
342
|
TLoaderDeps, TLoaderDataReturn, // TLoaderDataReturn,
|
|
333
343
|
TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'params'>;
|
|
334
|
-
export declare function createRootRouteWithContext<TRouterContext extends {}>(): <
|
|
344
|
+
export declare function createRootRouteWithContext<TRouterContext extends {}>(): <TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TRouteContextReturn extends RouteContext = RouteContext, TRouteContext extends RouteContext = ResolveRouteContext<TRouteContextReturn>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>>(options?: RootRouteOptions<TSearchValidator, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>) => RootRoute<TSearchValidator, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderData, ResolveLoaderData<TLoaderData>, unknown>;
|
|
335
345
|
/**
|
|
336
346
|
* @deprecated Use the `createRootRouteWithContext` function instead.
|
|
337
347
|
*/
|
|
338
348
|
export declare const rootRouteWithContext: typeof createRootRouteWithContext;
|
|
339
|
-
export declare class RootRoute<in out
|
|
349
|
+
export declare class RootRoute<in out TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TRouteContextReturn = RouteContext, in out TRouteContext = ResolveRouteContext<TRouteContextReturn>, in out TRouterContext = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, in out TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown> extends Route<any, // TParentRoute
|
|
340
350
|
'/', // TPath
|
|
341
351
|
'/', // TFullPath
|
|
342
352
|
string, // TCustomId
|
|
343
353
|
RootRouteId, // TId
|
|
344
|
-
|
|
345
|
-
TSearchSchema, // TSearchSchema
|
|
346
|
-
TSearchSchemaUsed, TSearchSchemaUsed, // TFullSearchSchemaInput
|
|
347
|
-
TSearchSchema, // TFullSearchSchema
|
|
354
|
+
TSearchValidator, // TSearchValidator
|
|
348
355
|
{}, // TParams
|
|
349
356
|
{}, // TAllParams
|
|
350
357
|
TRouteContextReturn, // TRouteContextReturn
|
|
@@ -354,20 +361,10 @@ TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren> {
|
|
|
354
361
|
/**
|
|
355
362
|
* @deprecated `RootRoute` is now an internal implementation detail. Use `createRootRoute()` instead.
|
|
356
363
|
*/
|
|
357
|
-
constructor(options?: RootRouteOptions<
|
|
358
|
-
addChildren<const TNewChildren extends Record<string, AnyRoute> | ReadonlyArray<AnyRoute>>(children: TNewChildren): RootRoute<
|
|
364
|
+
constructor(options?: RootRouteOptions<TSearchValidator, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>);
|
|
365
|
+
addChildren<const TNewChildren extends Record<string, AnyRoute> | ReadonlyArray<AnyRoute>>(children: TNewChildren): RootRoute<TSearchValidator, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TNewChildren>;
|
|
359
366
|
}
|
|
360
|
-
export declare function createRootRoute<
|
|
361
|
-
RootRouteId, // TCustomId
|
|
362
|
-
'', // TPath
|
|
363
|
-
TSearchSchemaInput, // TSearchSchemaInput
|
|
364
|
-
TSearchSchema, // TSearchSchema
|
|
365
|
-
TSearchSchema, {}, // TParams
|
|
366
|
-
{}, // TAllParams
|
|
367
|
-
TRouteContextReturn, // TRouteContextReturn
|
|
368
|
-
TRouteContext, // TRouteContext
|
|
369
|
-
TRouterContext, Assign<TRouterContext, TRouteContext>, // TAllContext
|
|
370
|
-
TLoaderDeps, TLoaderDataReturn, TLoaderData>, 'path' | 'id' | 'getParentRoute' | 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'params'>): RootRoute<TSearchSchemaInput, TSearchSchema, TSearchSchemaUsed, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, unknown>;
|
|
367
|
+
export declare function createRootRoute<TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TRouteContextReturn = RouteContext, TRouteContext = ResolveRouteContext<TRouteContextReturn>, TRouterContext = {}, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>>(options?: RootRouteOptions<TSearchValidator, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>): RootRoute<TSearchValidator, TRouteContextReturn, TRouteContext, TRouterContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, unknown>;
|
|
371
368
|
export type ResolveFullPath<TParentRoute extends AnyRoute, TPath extends string, TPrefixed = RoutePrefix<TParentRoute['fullPath'], TPath>> = TPrefixed extends RootRouteId ? '/' : TPrefixed;
|
|
372
369
|
type RoutePrefix<TPrefix extends string, TPath extends string> = string extends TPath ? RootRouteId : TPath extends string ? TPrefix extends RootRouteId ? TPath extends '/' ? '/' : `/${TrimPath<TPath>}` : `${TPrefix}/${TPath}` extends '/' ? '/' : `/${TrimPathLeft<`${TrimPathRight<TPrefix>}/${TrimPath<TPath>}`>}` : never;
|
|
373
370
|
export type TrimPath<T extends string> = '' extends T ? '' : TrimPathRight<TrimPathLeft<T>>;
|
|
@@ -414,7 +411,7 @@ export type AsyncRouteComponent<TProps> = SyncRouteComponent<TProps> & {
|
|
|
414
411
|
export type RouteComponent<TProps = any> = AsyncRouteComponent<TProps>;
|
|
415
412
|
export type ErrorRouteComponent = RouteComponent<ErrorComponentProps>;
|
|
416
413
|
export type NotFoundRouteComponent = SyncRouteComponent<NotFoundRouteProps>;
|
|
417
|
-
export declare class NotFoundRoute<TParentRoute extends AnyRootRoute,
|
|
418
|
-
constructor(options: Omit<RouteOptions<TParentRoute, string, string,
|
|
414
|
+
export declare class NotFoundRoute<TParentRoute extends AnyRootRoute, TSearchValidator extends AnySearchValidator = DefaultSearchValidator, TRouteContextReturn = AnyContext, TRouteContext = RouteContext, TAllContext = ResolveAllContext<TParentRoute, TRouteContext>, TLoaderDeps extends Record<string, any> = {}, TLoaderDataReturn = {}, TLoaderData = ResolveLoaderData<TLoaderDataReturn>, TChildren = unknown> extends Route<TParentRoute, '/404', '/404', '404', '404', TSearchValidator, {}, {}, TRouteContextReturn, TRouteContext, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData, TChildren> {
|
|
415
|
+
constructor(options: Omit<RouteOptions<TParentRoute, string, string, TSearchValidator, {}, {}, TRouteContextReturn, TRouteContext, InferAllContext<TParentRoute>, TAllContext, TLoaderDeps, TLoaderDataReturn, TLoaderData>, 'caseSensitive' | 'parseParams' | 'stringifyParams' | 'path' | 'id' | 'params'>);
|
|
419
416
|
}
|
|
420
417
|
export {};
|