@depup/tanstack__react-router 1.166.4-depup.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/LICENSE +21 -0
- package/README.md +32 -0
- package/dist/cjs/Asset.cjs +177 -0
- package/dist/cjs/Asset.cjs.map +1 -0
- package/dist/cjs/Asset.d.cts +5 -0
- package/dist/cjs/CatchBoundary.cjs +114 -0
- package/dist/cjs/CatchBoundary.cjs.map +1 -0
- package/dist/cjs/CatchBoundary.d.cts +12 -0
- package/dist/cjs/ClientOnly.cjs +21 -0
- package/dist/cjs/ClientOnly.cjs.map +1 -0
- package/dist/cjs/ClientOnly.d.cts +49 -0
- package/dist/cjs/HeadContent.cjs +15 -0
- package/dist/cjs/HeadContent.cjs.map +1 -0
- package/dist/cjs/HeadContent.d.cts +6 -0
- package/dist/cjs/HeadContent.dev.cjs +41 -0
- package/dist/cjs/HeadContent.dev.cjs.map +1 -0
- package/dist/cjs/HeadContent.dev.d.cts +10 -0
- package/dist/cjs/Match.cjs +255 -0
- package/dist/cjs/Match.cjs.map +1 -0
- package/dist/cjs/Match.d.cts +14 -0
- package/dist/cjs/Matches.cjs +138 -0
- package/dist/cjs/Matches.cjs.map +1 -0
- package/dist/cjs/Matches.d.cts +68 -0
- package/dist/cjs/RouterProvider.cjs +32 -0
- package/dist/cjs/RouterProvider.cjs.map +1 -0
- package/dist/cjs/RouterProvider.d.cts +23 -0
- package/dist/cjs/SafeFragment.cjs +8 -0
- package/dist/cjs/SafeFragment.cjs.map +1 -0
- package/dist/cjs/SafeFragment.d.cts +1 -0
- package/dist/cjs/ScriptOnce.cjs +22 -0
- package/dist/cjs/ScriptOnce.cjs.map +1 -0
- package/dist/cjs/ScriptOnce.d.cts +6 -0
- package/dist/cjs/Scripts.cjs +56 -0
- package/dist/cjs/Scripts.cjs.map +1 -0
- package/dist/cjs/Scripts.d.cts +5 -0
- package/dist/cjs/ScrollRestoration.cjs +38 -0
- package/dist/cjs/ScrollRestoration.cjs.map +1 -0
- package/dist/cjs/ScrollRestoration.d.cts +14 -0
- package/dist/cjs/Transitioner.cjs +119 -0
- package/dist/cjs/Transitioner.cjs.map +1 -0
- package/dist/cjs/Transitioner.d.cts +1 -0
- package/dist/cjs/awaited.cjs +51 -0
- package/dist/cjs/awaited.cjs.map +1 -0
- package/dist/cjs/awaited.d.cts +14 -0
- package/dist/cjs/fileRoute.cjs +109 -0
- package/dist/cjs/fileRoute.cjs.map +1 -0
- package/dist/cjs/fileRoute.d.cts +87 -0
- package/dist/cjs/headContentUtils.cjs +185 -0
- package/dist/cjs/headContentUtils.cjs.map +1 -0
- package/dist/cjs/headContentUtils.d.cts +7 -0
- package/dist/cjs/history.d.cts +8 -0
- package/dist/cjs/index.cjs +241 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/cjs/index.d.cts +51 -0
- package/dist/cjs/index.dev.cjs +241 -0
- package/dist/cjs/index.dev.cjs.map +1 -0
- package/dist/cjs/index.dev.d.cts +2 -0
- package/dist/cjs/lazyRouteComponent.cjs +70 -0
- package/dist/cjs/lazyRouteComponent.cjs.map +1 -0
- package/dist/cjs/lazyRouteComponent.d.cts +11 -0
- package/dist/cjs/link.cjs +573 -0
- package/dist/cjs/link.cjs.map +1 -0
- package/dist/cjs/link.d.cts +98 -0
- package/dist/cjs/matchContext.cjs +27 -0
- package/dist/cjs/matchContext.cjs.map +1 -0
- package/dist/cjs/matchContext.d.cts +3 -0
- package/dist/cjs/not-found.cjs +38 -0
- package/dist/cjs/not-found.cjs.map +1 -0
- package/dist/cjs/not-found.d.cts +9 -0
- package/dist/cjs/renderRouteNotFound.cjs +22 -0
- package/dist/cjs/renderRouteNotFound.cjs.map +1 -0
- package/dist/cjs/renderRouteNotFound.d.cts +10 -0
- package/dist/cjs/route.cjs +198 -0
- package/dist/cjs/route.cjs.map +1 -0
- package/dist/cjs/route.d.cts +142 -0
- package/dist/cjs/router.cjs +22 -0
- package/dist/cjs/router.cjs.map +1 -0
- package/dist/cjs/router.d.cts +83 -0
- package/dist/cjs/routerContext.cjs +23 -0
- package/dist/cjs/routerContext.cjs.map +1 -0
- package/dist/cjs/routerContext.d.cts +3 -0
- package/dist/cjs/scroll-restoration.cjs +39 -0
- package/dist/cjs/scroll-restoration.cjs.map +1 -0
- package/dist/cjs/scroll-restoration.d.cts +1 -0
- package/dist/cjs/ssr/RouterClient.cjs +25 -0
- package/dist/cjs/ssr/RouterClient.cjs.map +1 -0
- package/dist/cjs/ssr/RouterClient.d.cts +4 -0
- package/dist/cjs/ssr/RouterServer.cjs +9 -0
- package/dist/cjs/ssr/RouterServer.cjs.map +1 -0
- package/dist/cjs/ssr/RouterServer.d.cts +4 -0
- package/dist/cjs/ssr/client.cjs +12 -0
- package/dist/cjs/ssr/client.cjs.map +1 -0
- package/dist/cjs/ssr/client.d.cts +2 -0
- package/dist/cjs/ssr/defaultRenderHandler.cjs +15 -0
- package/dist/cjs/ssr/defaultRenderHandler.cjs.map +1 -0
- package/dist/cjs/ssr/defaultRenderHandler.d.cts +1 -0
- package/dist/cjs/ssr/defaultStreamHandler.cjs +16 -0
- package/dist/cjs/ssr/defaultStreamHandler.cjs.map +1 -0
- package/dist/cjs/ssr/defaultStreamHandler.d.cts +1 -0
- package/dist/cjs/ssr/renderRouterToStream.cjs +73 -0
- package/dist/cjs/ssr/renderRouterToStream.cjs.map +1 -0
- package/dist/cjs/ssr/renderRouterToStream.d.cts +8 -0
- package/dist/cjs/ssr/renderRouterToString.cjs +31 -0
- package/dist/cjs/ssr/renderRouterToString.cjs.map +1 -0
- package/dist/cjs/ssr/renderRouterToString.d.cts +7 -0
- package/dist/cjs/ssr/serializer.d.cts +6 -0
- package/dist/cjs/ssr/server.cjs +20 -0
- package/dist/cjs/ssr/server.cjs.map +1 -0
- package/dist/cjs/ssr/server.d.cts +6 -0
- package/dist/cjs/structuralSharing.d.cts +8 -0
- package/dist/cjs/typePrimitives.d.cts +16 -0
- package/dist/cjs/useBlocker.cjs +171 -0
- package/dist/cjs/useBlocker.cjs.map +1 -0
- package/dist/cjs/useBlocker.d.cts +66 -0
- package/dist/cjs/useCanGoBack.cjs +8 -0
- package/dist/cjs/useCanGoBack.cjs.map +1 -0
- package/dist/cjs/useCanGoBack.d.cts +1 -0
- package/dist/cjs/useLoaderData.cjs +15 -0
- package/dist/cjs/useLoaderData.cjs.map +1 -0
- package/dist/cjs/useLoaderData.d.cts +19 -0
- package/dist/cjs/useLoaderDeps.cjs +14 -0
- package/dist/cjs/useLoaderDeps.cjs.map +1 -0
- package/dist/cjs/useLoaderDeps.d.cts +19 -0
- package/dist/cjs/useLocation.cjs +10 -0
- package/dist/cjs/useLocation.cjs.map +1 -0
- package/dist/cjs/useLocation.d.cts +18 -0
- package/dist/cjs/useMatch.cjs +47 -0
- package/dist/cjs/useMatch.cjs.map +1 -0
- package/dist/cjs/useMatch.d.cts +14 -0
- package/dist/cjs/useNavigate.cjs +49 -0
- package/dist/cjs/useNavigate.cjs.map +1 -0
- package/dist/cjs/useNavigate.d.cts +28 -0
- package/dist/cjs/useParams.cjs +17 -0
- package/dist/cjs/useParams.cjs.map +1 -0
- package/dist/cjs/useParams.d.cts +21 -0
- package/dist/cjs/useRouteContext.cjs +11 -0
- package/dist/cjs/useRouteContext.cjs.map +1 -0
- package/dist/cjs/useRouteContext.d.cts +3 -0
- package/dist/cjs/useRouter.cjs +32 -0
- package/dist/cjs/useRouter.cjs.map +1 -0
- package/dist/cjs/useRouter.d.cts +14 -0
- package/dist/cjs/useRouterState.cjs +38 -0
- package/dist/cjs/useRouterState.cjs.map +1 -0
- package/dist/cjs/useRouterState.d.cts +20 -0
- package/dist/cjs/useSearch.cjs +16 -0
- package/dist/cjs/useSearch.cjs.map +1 -0
- package/dist/cjs/useSearch.d.cts +21 -0
- package/dist/cjs/utils.cjs +62 -0
- package/dist/cjs/utils.cjs.map +1 -0
- package/dist/cjs/utils.d.cts +54 -0
- package/dist/esm/Asset.d.ts +5 -0
- package/dist/esm/Asset.js +160 -0
- package/dist/esm/Asset.js.map +1 -0
- package/dist/esm/CatchBoundary.d.ts +12 -0
- package/dist/esm/CatchBoundary.js +97 -0
- package/dist/esm/CatchBoundary.js.map +1 -0
- package/dist/esm/ClientOnly.d.ts +49 -0
- package/dist/esm/ClientOnly.js +21 -0
- package/dist/esm/ClientOnly.js.map +1 -0
- package/dist/esm/HeadContent.d.ts +6 -0
- package/dist/esm/HeadContent.dev.d.ts +10 -0
- package/dist/esm/HeadContent.dev.js +25 -0
- package/dist/esm/HeadContent.dev.js.map +1 -0
- package/dist/esm/HeadContent.js +15 -0
- package/dist/esm/HeadContent.js.map +1 -0
- package/dist/esm/Match.d.ts +14 -0
- package/dist/esm/Match.js +238 -0
- package/dist/esm/Match.js.map +1 -0
- package/dist/esm/Matches.d.ts +68 -0
- package/dist/esm/Matches.js +121 -0
- package/dist/esm/Matches.js.map +1 -0
- package/dist/esm/RouterProvider.d.ts +23 -0
- package/dist/esm/RouterProvider.js +32 -0
- package/dist/esm/RouterProvider.js.map +1 -0
- package/dist/esm/SafeFragment.d.ts +1 -0
- package/dist/esm/SafeFragment.js +8 -0
- package/dist/esm/SafeFragment.js.map +1 -0
- package/dist/esm/ScriptOnce.d.ts +6 -0
- package/dist/esm/ScriptOnce.js +22 -0
- package/dist/esm/ScriptOnce.js.map +1 -0
- package/dist/esm/Scripts.d.ts +5 -0
- package/dist/esm/Scripts.js +56 -0
- package/dist/esm/Scripts.js.map +1 -0
- package/dist/esm/ScrollRestoration.d.ts +14 -0
- package/dist/esm/ScrollRestoration.js +38 -0
- package/dist/esm/ScrollRestoration.js.map +1 -0
- package/dist/esm/Transitioner.d.ts +1 -0
- package/dist/esm/Transitioner.js +102 -0
- package/dist/esm/Transitioner.js.map +1 -0
- package/dist/esm/awaited.d.ts +14 -0
- package/dist/esm/awaited.js +34 -0
- package/dist/esm/awaited.js.map +1 -0
- package/dist/esm/fileRoute.d.ts +87 -0
- package/dist/esm/fileRoute.js +109 -0
- package/dist/esm/fileRoute.js.map +1 -0
- package/dist/esm/headContentUtils.d.ts +7 -0
- package/dist/esm/headContentUtils.js +168 -0
- package/dist/esm/headContentUtils.js.map +1 -0
- package/dist/esm/history.d.ts +8 -0
- package/dist/esm/index.d.ts +51 -0
- package/dist/esm/index.dev.d.ts +2 -0
- package/dist/esm/index.dev.js +133 -0
- package/dist/esm/index.dev.js.map +1 -0
- package/dist/esm/index.js +133 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lazyRouteComponent.d.ts +11 -0
- package/dist/esm/lazyRouteComponent.js +53 -0
- package/dist/esm/lazyRouteComponent.js.map +1 -0
- package/dist/esm/link.d.ts +98 -0
- package/dist/esm/link.js +556 -0
- package/dist/esm/link.js.map +1 -0
- package/dist/esm/matchContext.d.ts +3 -0
- package/dist/esm/matchContext.js +10 -0
- package/dist/esm/matchContext.js.map +1 -0
- package/dist/esm/not-found.d.ts +9 -0
- package/dist/esm/not-found.js +38 -0
- package/dist/esm/not-found.js.map +1 -0
- package/dist/esm/renderRouteNotFound.d.ts +10 -0
- package/dist/esm/renderRouteNotFound.js +22 -0
- package/dist/esm/renderRouteNotFound.js.map +1 -0
- package/dist/esm/route.d.ts +142 -0
- package/dist/esm/route.js +198 -0
- package/dist/esm/route.js.map +1 -0
- package/dist/esm/router.d.ts +83 -0
- package/dist/esm/router.js +22 -0
- package/dist/esm/router.js.map +1 -0
- package/dist/esm/routerContext.d.ts +3 -0
- package/dist/esm/routerContext.js +6 -0
- package/dist/esm/routerContext.js.map +1 -0
- package/dist/esm/scroll-restoration.d.ts +1 -0
- package/dist/esm/scroll-restoration.js +39 -0
- package/dist/esm/scroll-restoration.js.map +1 -0
- package/dist/esm/ssr/RouterClient.d.ts +4 -0
- package/dist/esm/ssr/RouterClient.js +25 -0
- package/dist/esm/ssr/RouterClient.js.map +1 -0
- package/dist/esm/ssr/RouterServer.d.ts +4 -0
- package/dist/esm/ssr/RouterServer.js +9 -0
- package/dist/esm/ssr/RouterServer.js.map +1 -0
- package/dist/esm/ssr/client.d.ts +2 -0
- package/dist/esm/ssr/client.js +6 -0
- package/dist/esm/ssr/client.js.map +1 -0
- package/dist/esm/ssr/defaultRenderHandler.d.ts +1 -0
- package/dist/esm/ssr/defaultRenderHandler.js +15 -0
- package/dist/esm/ssr/defaultRenderHandler.js.map +1 -0
- package/dist/esm/ssr/defaultStreamHandler.d.ts +1 -0
- package/dist/esm/ssr/defaultStreamHandler.js +16 -0
- package/dist/esm/ssr/defaultStreamHandler.js.map +1 -0
- package/dist/esm/ssr/renderRouterToStream.d.ts +8 -0
- package/dist/esm/ssr/renderRouterToStream.js +73 -0
- package/dist/esm/ssr/renderRouterToStream.js.map +1 -0
- package/dist/esm/ssr/renderRouterToString.d.ts +7 -0
- package/dist/esm/ssr/renderRouterToString.js +31 -0
- package/dist/esm/ssr/renderRouterToString.js.map +1 -0
- package/dist/esm/ssr/serializer.d.ts +6 -0
- package/dist/esm/ssr/server.d.ts +6 -0
- package/dist/esm/ssr/server.js +14 -0
- package/dist/esm/ssr/server.js.map +1 -0
- package/dist/esm/structuralSharing.d.ts +8 -0
- package/dist/esm/typePrimitives.d.ts +16 -0
- package/dist/esm/useBlocker.d.ts +66 -0
- package/dist/esm/useBlocker.js +154 -0
- package/dist/esm/useBlocker.js.map +1 -0
- package/dist/esm/useCanGoBack.d.ts +1 -0
- package/dist/esm/useCanGoBack.js +8 -0
- package/dist/esm/useCanGoBack.js.map +1 -0
- package/dist/esm/useLoaderData.d.ts +19 -0
- package/dist/esm/useLoaderData.js +15 -0
- package/dist/esm/useLoaderData.js.map +1 -0
- package/dist/esm/useLoaderDeps.d.ts +19 -0
- package/dist/esm/useLoaderDeps.js +14 -0
- package/dist/esm/useLoaderDeps.js.map +1 -0
- package/dist/esm/useLocation.d.ts +18 -0
- package/dist/esm/useLocation.js +10 -0
- package/dist/esm/useLocation.js.map +1 -0
- package/dist/esm/useMatch.d.ts +14 -0
- package/dist/esm/useMatch.js +30 -0
- package/dist/esm/useMatch.js.map +1 -0
- package/dist/esm/useNavigate.d.ts +28 -0
- package/dist/esm/useNavigate.js +32 -0
- package/dist/esm/useNavigate.js.map +1 -0
- package/dist/esm/useParams.d.ts +21 -0
- package/dist/esm/useParams.js +17 -0
- package/dist/esm/useParams.js.map +1 -0
- package/dist/esm/useRouteContext.d.ts +3 -0
- package/dist/esm/useRouteContext.js +11 -0
- package/dist/esm/useRouteContext.js.map +1 -0
- package/dist/esm/useRouter.d.ts +14 -0
- package/dist/esm/useRouter.js +15 -0
- package/dist/esm/useRouter.js.map +1 -0
- package/dist/esm/useRouterState.d.ts +20 -0
- package/dist/esm/useRouterState.js +38 -0
- package/dist/esm/useRouterState.js.map +1 -0
- package/dist/esm/useSearch.d.ts +21 -0
- package/dist/esm/useSearch.js +16 -0
- package/dist/esm/useSearch.js.map +1 -0
- package/dist/esm/utils.d.ts +54 -0
- package/dist/esm/utils.js +45 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/llms/index.d.ts +3 -0
- package/dist/llms/index.js +43 -0
- package/dist/llms/rules/api.d.ts +2 -0
- package/dist/llms/rules/api.js +4612 -0
- package/dist/llms/rules/guide.d.ts +2 -0
- package/dist/llms/rules/guide.js +10690 -0
- package/dist/llms/rules/installation.d.ts +2 -0
- package/dist/llms/rules/installation.js +1285 -0
- package/dist/llms/rules/routing.d.ts +2 -0
- package/dist/llms/rules/routing.js +1984 -0
- package/dist/llms/rules/setup-and-architecture.d.ts +2 -0
- package/dist/llms/rules/setup-and-architecture.js +920 -0
- package/package.json +142 -0
- package/src/Asset.tsx +219 -0
- package/src/CatchBoundary.tsx +120 -0
- package/src/ClientOnly.tsx +68 -0
- package/src/HeadContent.dev.tsx +46 -0
- package/src/HeadContent.tsx +22 -0
- package/src/Match.tsx +360 -0
- package/src/Matches.tsx +313 -0
- package/src/RouterProvider.tsx +92 -0
- package/src/SafeFragment.tsx +5 -0
- package/src/ScriptOnce.tsx +21 -0
- package/src/Scripts.tsx +80 -0
- package/src/ScrollRestoration.tsx +69 -0
- package/src/Transitioner.tsx +134 -0
- package/src/awaited.tsx +55 -0
- package/src/fileRoute.ts +313 -0
- package/src/headContentUtils.tsx +217 -0
- package/src/history.ts +9 -0
- package/src/index.dev.tsx +6 -0
- package/src/index.tsx +341 -0
- package/src/lazyRouteComponent.tsx +96 -0
- package/src/link.tsx +984 -0
- package/src/matchContext.tsx +8 -0
- package/src/not-found.tsx +43 -0
- package/src/renderRouteNotFound.tsx +35 -0
- package/src/route.tsx +740 -0
- package/src/router.ts +127 -0
- package/src/routerContext.tsx +4 -0
- package/src/scroll-restoration.tsx +45 -0
- package/src/ssr/RouterClient.tsx +22 -0
- package/src/ssr/RouterServer.tsx +9 -0
- package/src/ssr/client.ts +2 -0
- package/src/ssr/defaultRenderHandler.tsx +12 -0
- package/src/ssr/defaultStreamHandler.tsx +13 -0
- package/src/ssr/renderRouterToStream.tsx +90 -0
- package/src/ssr/renderRouterToString.tsx +36 -0
- package/src/ssr/serializer.ts +7 -0
- package/src/ssr/server.ts +6 -0
- package/src/structuralSharing.ts +47 -0
- package/src/typePrimitives.ts +84 -0
- package/src/useBlocker.tsx +320 -0
- package/src/useCanGoBack.ts +5 -0
- package/src/useLoaderData.tsx +91 -0
- package/src/useLoaderDeps.tsx +69 -0
- package/src/useLocation.tsx +52 -0
- package/src/useMatch.tsx +123 -0
- package/src/useNavigate.tsx +78 -0
- package/src/useParams.tsx +107 -0
- package/src/useRouteContext.ts +30 -0
- package/src/useRouter.tsx +25 -0
- package/src/useRouterState.tsx +86 -0
- package/src/useSearch.tsx +105 -0
- package/src/utils.ts +125 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
export interface ClientOnlyProps {
|
|
3
|
+
/**
|
|
4
|
+
* The children to render when the JS is loaded.
|
|
5
|
+
*/
|
|
6
|
+
children: React.ReactNode;
|
|
7
|
+
/**
|
|
8
|
+
* The fallback component to render if the JS is not yet loaded.
|
|
9
|
+
*/
|
|
10
|
+
fallback?: React.ReactNode;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Render the children only after the JS has loaded client-side. Use an optional
|
|
14
|
+
* fallback component if the JS is not yet loaded.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* Render a Chart component if JS loads, renders a simple FakeChart
|
|
18
|
+
* component server-side or if there is no JS. The FakeChart can have only the
|
|
19
|
+
* UI without the behavior or be a loading spinner or skeleton.
|
|
20
|
+
*
|
|
21
|
+
* ```tsx
|
|
22
|
+
* return (
|
|
23
|
+
* <ClientOnly fallback={<FakeChart />}>
|
|
24
|
+
* <Chart />
|
|
25
|
+
* </ClientOnly>
|
|
26
|
+
* )
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function ClientOnly({ children, fallback }: ClientOnlyProps): import("react/jsx-runtime").JSX.Element;
|
|
30
|
+
/**
|
|
31
|
+
* Return a boolean indicating if the JS has been hydrated already.
|
|
32
|
+
* When doing Server-Side Rendering, the result will always be false.
|
|
33
|
+
* When doing Client-Side Rendering, the result will always be false on the
|
|
34
|
+
* first render and true from then on. Even if a new component renders it will
|
|
35
|
+
* always start with true.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```tsx
|
|
39
|
+
* // Disable a button that needs JS to work.
|
|
40
|
+
* let hydrated = useHydrated()
|
|
41
|
+
* return (
|
|
42
|
+
* <button type="button" disabled={!hydrated} onClick={doSomethingCustom}>
|
|
43
|
+
* Click me
|
|
44
|
+
* </button>
|
|
45
|
+
* )
|
|
46
|
+
* ```
|
|
47
|
+
* @returns True if the JS has been hydrated already, false otherwise.
|
|
48
|
+
*/
|
|
49
|
+
export declare function useHydrated(): boolean;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import React__default from "react";
|
|
3
|
+
function ClientOnly({ children, fallback = null }) {
|
|
4
|
+
return useHydrated() ? /* @__PURE__ */ jsx(React__default.Fragment, { children }) : /* @__PURE__ */ jsx(React__default.Fragment, { children: fallback });
|
|
5
|
+
}
|
|
6
|
+
function useHydrated() {
|
|
7
|
+
return React__default.useSyncExternalStore(
|
|
8
|
+
subscribe,
|
|
9
|
+
() => true,
|
|
10
|
+
() => false
|
|
11
|
+
);
|
|
12
|
+
}
|
|
13
|
+
function subscribe() {
|
|
14
|
+
return () => {
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
export {
|
|
18
|
+
ClientOnly,
|
|
19
|
+
useHydrated
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=ClientOnly.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ClientOnly.js","sources":["../../src/ClientOnly.tsx"],"sourcesContent":["import React from 'react'\n\nexport interface ClientOnlyProps {\n /**\n * The children to render when the JS is loaded.\n */\n children: React.ReactNode\n /**\n * The fallback component to render if the JS is not yet loaded.\n */\n fallback?: React.ReactNode\n}\n\n/**\n * Render the children only after the JS has loaded client-side. Use an optional\n * fallback component if the JS is not yet loaded.\n *\n * @example\n * Render a Chart component if JS loads, renders a simple FakeChart\n * component server-side or if there is no JS. The FakeChart can have only the\n * UI without the behavior or be a loading spinner or skeleton.\n *\n * ```tsx\n * return (\n * <ClientOnly fallback={<FakeChart />}>\n * <Chart />\n * </ClientOnly>\n * )\n * ```\n */\nexport function ClientOnly({ children, fallback = null }: ClientOnlyProps) {\n return useHydrated() ? (\n <React.Fragment>{children}</React.Fragment>\n ) : (\n <React.Fragment>{fallback}</React.Fragment>\n )\n}\n\n/**\n * Return a boolean indicating if the JS has been hydrated already.\n * When doing Server-Side Rendering, the result will always be false.\n * When doing Client-Side Rendering, the result will always be false on the\n * first render and true from then on. Even if a new component renders it will\n * always start with true.\n *\n * @example\n * ```tsx\n * // Disable a button that needs JS to work.\n * let hydrated = useHydrated()\n * return (\n * <button type=\"button\" disabled={!hydrated} onClick={doSomethingCustom}>\n * Click me\n * </button>\n * )\n * ```\n * @returns True if the JS has been hydrated already, false otherwise.\n */\nexport function useHydrated(): boolean {\n return React.useSyncExternalStore(\n subscribe,\n () => true,\n () => false,\n )\n}\n\nfunction subscribe() {\n return () => {}\n}\n"],"names":["React"],"mappings":";;AA8BO,SAAS,WAAW,EAAE,UAAU,WAAW,QAAyB;AACzE,SAAO,YAAA,IACL,oBAACA,eAAM,UAAN,EAAgB,SAAA,CAAS,IAE1B,oBAACA,eAAM,UAAN,EAAgB,UAAA,SAAA,CAAS;AAE9B;AAqBO,SAAS,cAAuB;AACrC,SAAOA,eAAM;AAAA,IACX;AAAA,IACA,MAAM;AAAA,IACN,MAAM;AAAA,EAAA;AAEV;AAEA,SAAS,YAAY;AACnB,SAAO,MAAM;AAAA,EAAC;AAChB;"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render route-managed head tags (title, meta, links, styles, head scripts).
|
|
3
|
+
* Place inside the document head of your app shell.
|
|
4
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management
|
|
5
|
+
*/
|
|
6
|
+
export declare function HeadContent(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Render route-managed head tags (title, meta, links, styles, head scripts).
|
|
3
|
+
* Place inside the document head of your app shell.
|
|
4
|
+
*
|
|
5
|
+
* Development version: filters out dev styles link after hydration and
|
|
6
|
+
* includes a fallback cleanup effect for hydration mismatch cases.
|
|
7
|
+
*
|
|
8
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management
|
|
9
|
+
*/
|
|
10
|
+
export declare function HeadContent(): import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { Asset } from "./Asset.js";
|
|
5
|
+
import { useRouter } from "./useRouter.js";
|
|
6
|
+
import { useHydrated } from "./ClientOnly.js";
|
|
7
|
+
import { useTags } from "./headContentUtils.js";
|
|
8
|
+
const DEV_STYLES_ATTR = "data-tanstack-router-dev-styles";
|
|
9
|
+
function HeadContent() {
|
|
10
|
+
const tags = useTags();
|
|
11
|
+
const router = useRouter();
|
|
12
|
+
const nonce = router.options.ssr?.nonce;
|
|
13
|
+
const hydrated = useHydrated();
|
|
14
|
+
React.useEffect(() => {
|
|
15
|
+
if (hydrated) {
|
|
16
|
+
document.querySelectorAll(`link[${DEV_STYLES_ATTR}]`).forEach((el) => el.remove());
|
|
17
|
+
}
|
|
18
|
+
}, [hydrated]);
|
|
19
|
+
const filteredTags = hydrated ? tags.filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR]) : tags;
|
|
20
|
+
return /* @__PURE__ */ jsx(Fragment, { children: filteredTags.map((tag) => /* @__PURE__ */ createElement(Asset, { ...tag, key: `tsr-meta-${JSON.stringify(tag)}`, nonce })) });
|
|
21
|
+
}
|
|
22
|
+
export {
|
|
23
|
+
HeadContent
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=HeadContent.dev.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeadContent.dev.js","sources":["../../src/HeadContent.dev.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport { useHydrated } from './ClientOnly'\nimport { useTags } from './headContentUtils'\n\nconst DEV_STYLES_ATTR = 'data-tanstack-router-dev-styles'\n\n/**\n * Render route-managed head tags (title, meta, links, styles, head scripts).\n * Place inside the document head of your app shell.\n *\n * Development version: filters out dev styles link after hydration and\n * includes a fallback cleanup effect for hydration mismatch cases.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management\n */\nexport function HeadContent() {\n const tags = useTags()\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n const hydrated = useHydrated()\n\n // Fallback cleanup for hydration mismatch cases\n // Runs when hydration completes to remove any orphaned dev styles links from DOM\n React.useEffect(() => {\n if (hydrated) {\n document\n .querySelectorAll(`link[${DEV_STYLES_ATTR}]`)\n .forEach((el) => el.remove())\n }\n }, [hydrated])\n\n // Filter out dev styles after hydration\n const filteredTags = hydrated\n ? tags.filter((tag) => !tag.attrs?.[DEV_STYLES_ATTR])\n : tags\n\n return (\n <>\n {filteredTags.map((tag) => (\n <Asset {...tag} key={`tsr-meta-${JSON.stringify(tag)}`} nonce={nonce} />\n ))}\n </>\n )\n}\n"],"names":[],"mappings":";;;;;;;AAMA,MAAM,kBAAkB;AAWjB,SAAS,cAAc;AAC5B,QAAM,OAAO,QAAA;AACb,QAAM,SAAS,UAAA;AACf,QAAM,QAAQ,OAAO,QAAQ,KAAK;AAClC,QAAM,WAAW,YAAA;AAIjB,QAAM,UAAU,MAAM;AACpB,QAAI,UAAU;AACZ,eACG,iBAAiB,QAAQ,eAAe,GAAG,EAC3C,QAAQ,CAAC,OAAO,GAAG,OAAA,CAAQ;AAAA,IAChC;AAAA,EACF,GAAG,CAAC,QAAQ,CAAC;AAGb,QAAM,eAAe,WACjB,KAAK,OAAO,CAAC,QAAQ,CAAC,IAAI,QAAQ,eAAe,CAAC,IAClD;AAEJ,yCAEK,UAAA,aAAa,IAAI,CAAC,QACjB,8BAAC,SAAO,GAAG,KAAK,KAAK,YAAY,KAAK,UAAU,GAAG,CAAC,IAAI,OAAc,CACvE,GACH;AAEJ;"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import { createElement } from "react";
|
|
3
|
+
import { Asset } from "./Asset.js";
|
|
4
|
+
import { useRouter } from "./useRouter.js";
|
|
5
|
+
import { useTags } from "./headContentUtils.js";
|
|
6
|
+
function HeadContent() {
|
|
7
|
+
const tags = useTags();
|
|
8
|
+
const router = useRouter();
|
|
9
|
+
const nonce = router.options.ssr?.nonce;
|
|
10
|
+
return /* @__PURE__ */ jsx(Fragment, { children: tags.map((tag) => /* @__PURE__ */ createElement(Asset, { ...tag, key: `tsr-meta-${JSON.stringify(tag)}`, nonce })) });
|
|
11
|
+
}
|
|
12
|
+
export {
|
|
13
|
+
HeadContent
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=HeadContent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HeadContent.js","sources":["../../src/HeadContent.tsx"],"sourcesContent":["import * as React from 'react'\nimport { Asset } from './Asset'\nimport { useRouter } from './useRouter'\nimport { useTags } from './headContentUtils'\n\n/**\n * Render route-managed head tags (title, meta, links, styles, head scripts).\n * Place inside the document head of your app shell.\n * @link https://tanstack.com/router/latest/docs/framework/react/guide/document-head-management\n */\nexport function HeadContent() {\n const tags = useTags()\n const router = useRouter()\n const nonce = router.options.ssr?.nonce\n return (\n <>\n {tags.map((tag) => (\n <Asset {...tag} key={`tsr-meta-${JSON.stringify(tag)}`} nonce={nonce} />\n ))}\n </>\n )\n}\n"],"names":[],"mappings":";;;;;AAUO,SAAS,cAAc;AAC5B,QAAM,OAAO,QAAA;AACb,QAAM,SAAS,UAAA;AACf,QAAM,QAAQ,OAAO,QAAQ,KAAK;AAClC,yCAEK,UAAA,KAAK,IAAI,CAAC,QACT,8BAAC,SAAO,GAAG,KAAK,KAAK,YAAY,KAAK,UAAU,GAAG,CAAC,IAAI,OAAc,CACvE,GACH;AAEJ;"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export declare const Match: React.NamedExoticComponent<{
|
|
3
|
+
matchId: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare const MatchInner: React.NamedExoticComponent<{
|
|
6
|
+
matchId: string;
|
|
7
|
+
}>;
|
|
8
|
+
/**
|
|
9
|
+
* Render the next child match in the route tree. Typically used inside
|
|
10
|
+
* a route component to render nested routes.
|
|
11
|
+
*
|
|
12
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent
|
|
13
|
+
*/
|
|
14
|
+
export declare const Outlet: React.NamedExoticComponent<object>;
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import { jsxs, jsx, Fragment } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import invariant from "tiny-invariant";
|
|
4
|
+
import warning from "tiny-warning";
|
|
5
|
+
import { isNotFound, rootRouteId, createControlledPromise, isRedirect, getLocationChangeInfo } from "@tanstack/router-core";
|
|
6
|
+
import { isServer } from "@tanstack/router-core/isServer";
|
|
7
|
+
import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
|
|
8
|
+
import { useRouterState } from "./useRouterState.js";
|
|
9
|
+
import { useRouter } from "./useRouter.js";
|
|
10
|
+
import { CatchNotFound } from "./not-found.js";
|
|
11
|
+
import { matchContext } from "./matchContext.js";
|
|
12
|
+
import { SafeFragment } from "./SafeFragment.js";
|
|
13
|
+
import { renderRouteNotFound } from "./renderRouteNotFound.js";
|
|
14
|
+
import { ScrollRestoration } from "./scroll-restoration.js";
|
|
15
|
+
import { ClientOnly } from "./ClientOnly.js";
|
|
16
|
+
const Match = React.memo(function MatchImpl({
|
|
17
|
+
matchId
|
|
18
|
+
}) {
|
|
19
|
+
const router = useRouter();
|
|
20
|
+
const matchState = useRouterState({
|
|
21
|
+
select: (s) => {
|
|
22
|
+
const matchIndex = s.matches.findIndex((d) => d.id === matchId);
|
|
23
|
+
const match = s.matches[matchIndex];
|
|
24
|
+
invariant(
|
|
25
|
+
match,
|
|
26
|
+
`Could not find match for matchId "${matchId}". Please file an issue!`
|
|
27
|
+
);
|
|
28
|
+
return {
|
|
29
|
+
routeId: match.routeId,
|
|
30
|
+
ssr: match.ssr,
|
|
31
|
+
_displayPending: match._displayPending,
|
|
32
|
+
resetKey: s.loadedAt,
|
|
33
|
+
parentRouteId: s.matches[matchIndex - 1]?.routeId
|
|
34
|
+
};
|
|
35
|
+
},
|
|
36
|
+
structuralSharing: true
|
|
37
|
+
});
|
|
38
|
+
const route = router.routesById[matchState.routeId];
|
|
39
|
+
const PendingComponent = route.options.pendingComponent ?? router.options.defaultPendingComponent;
|
|
40
|
+
const pendingElement = PendingComponent ? /* @__PURE__ */ jsx(PendingComponent, {}) : null;
|
|
41
|
+
const routeErrorComponent = route.options.errorComponent ?? router.options.defaultErrorComponent;
|
|
42
|
+
const routeOnCatch = route.options.onCatch ?? router.options.defaultOnCatch;
|
|
43
|
+
const routeNotFoundComponent = route.isRoot ? (
|
|
44
|
+
// If it's the root route, use the globalNotFound option, with fallback to the notFoundRoute's component
|
|
45
|
+
route.options.notFoundComponent ?? router.options.notFoundRoute?.options.component
|
|
46
|
+
) : route.options.notFoundComponent;
|
|
47
|
+
const resolvedNoSsr = matchState.ssr === false || matchState.ssr === "data-only";
|
|
48
|
+
const ResolvedSuspenseBoundary = (
|
|
49
|
+
// If we're on the root route, allow forcefully wrapping in suspense
|
|
50
|
+
(!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) && (route.options.wrapInSuspense ?? PendingComponent ?? (route.options.errorComponent?.preload || resolvedNoSsr)) ? React.Suspense : SafeFragment
|
|
51
|
+
);
|
|
52
|
+
const ResolvedCatchBoundary = routeErrorComponent ? CatchBoundary : SafeFragment;
|
|
53
|
+
const ResolvedNotFoundBoundary = routeNotFoundComponent ? CatchNotFound : SafeFragment;
|
|
54
|
+
const ShellComponent = route.isRoot ? route.options.shellComponent ?? SafeFragment : SafeFragment;
|
|
55
|
+
return /* @__PURE__ */ jsxs(ShellComponent, { children: [
|
|
56
|
+
/* @__PURE__ */ jsx(matchContext.Provider, { value: matchId, children: /* @__PURE__ */ jsx(ResolvedSuspenseBoundary, { fallback: pendingElement, children: /* @__PURE__ */ jsx(
|
|
57
|
+
ResolvedCatchBoundary,
|
|
58
|
+
{
|
|
59
|
+
getResetKey: () => matchState.resetKey,
|
|
60
|
+
errorComponent: routeErrorComponent || ErrorComponent,
|
|
61
|
+
onCatch: (error, errorInfo) => {
|
|
62
|
+
if (isNotFound(error)) throw error;
|
|
63
|
+
warning(false, `Error in route match: ${matchId}`);
|
|
64
|
+
routeOnCatch?.(error, errorInfo);
|
|
65
|
+
},
|
|
66
|
+
children: /* @__PURE__ */ jsx(
|
|
67
|
+
ResolvedNotFoundBoundary,
|
|
68
|
+
{
|
|
69
|
+
fallback: (error) => {
|
|
70
|
+
if (!routeNotFoundComponent || error.routeId && error.routeId !== matchState.routeId || !error.routeId && !route.isRoot)
|
|
71
|
+
throw error;
|
|
72
|
+
return React.createElement(routeNotFoundComponent, error);
|
|
73
|
+
},
|
|
74
|
+
children: resolvedNoSsr || matchState._displayPending ? /* @__PURE__ */ jsx(ClientOnly, { fallback: pendingElement, children: /* @__PURE__ */ jsx(MatchInner, { matchId }) }) : /* @__PURE__ */ jsx(MatchInner, { matchId })
|
|
75
|
+
}
|
|
76
|
+
)
|
|
77
|
+
}
|
|
78
|
+
) }) }),
|
|
79
|
+
matchState.parentRouteId === rootRouteId && router.options.scrollRestoration ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
80
|
+
/* @__PURE__ */ jsx(OnRendered, {}),
|
|
81
|
+
/* @__PURE__ */ jsx(ScrollRestoration, {})
|
|
82
|
+
] }) : null
|
|
83
|
+
] });
|
|
84
|
+
});
|
|
85
|
+
function OnRendered() {
|
|
86
|
+
const router = useRouter();
|
|
87
|
+
const prevLocationRef = React.useRef(
|
|
88
|
+
void 0
|
|
89
|
+
);
|
|
90
|
+
return /* @__PURE__ */ jsx(
|
|
91
|
+
"script",
|
|
92
|
+
{
|
|
93
|
+
suppressHydrationWarning: true,
|
|
94
|
+
ref: (el) => {
|
|
95
|
+
if (el && (prevLocationRef.current === void 0 || prevLocationRef.current.href !== router.latestLocation.href)) {
|
|
96
|
+
router.emit({
|
|
97
|
+
type: "onRendered",
|
|
98
|
+
...getLocationChangeInfo(router.state)
|
|
99
|
+
});
|
|
100
|
+
prevLocationRef.current = router.latestLocation;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
router.latestLocation.state.__TSR_key
|
|
105
|
+
);
|
|
106
|
+
}
|
|
107
|
+
const MatchInner = React.memo(function MatchInnerImpl({
|
|
108
|
+
matchId
|
|
109
|
+
}) {
|
|
110
|
+
const router = useRouter();
|
|
111
|
+
const { match, key, routeId } = useRouterState({
|
|
112
|
+
select: (s) => {
|
|
113
|
+
const match2 = s.matches.find((d) => d.id === matchId);
|
|
114
|
+
const routeId2 = match2.routeId;
|
|
115
|
+
const remountFn = router.routesById[routeId2].options.remountDeps ?? router.options.defaultRemountDeps;
|
|
116
|
+
const remountDeps = remountFn?.({
|
|
117
|
+
routeId: routeId2,
|
|
118
|
+
loaderDeps: match2.loaderDeps,
|
|
119
|
+
params: match2._strictParams,
|
|
120
|
+
search: match2._strictSearch
|
|
121
|
+
});
|
|
122
|
+
const key2 = remountDeps ? JSON.stringify(remountDeps) : void 0;
|
|
123
|
+
return {
|
|
124
|
+
key: key2,
|
|
125
|
+
routeId: routeId2,
|
|
126
|
+
match: {
|
|
127
|
+
id: match2.id,
|
|
128
|
+
status: match2.status,
|
|
129
|
+
error: match2.error,
|
|
130
|
+
invalid: match2.invalid,
|
|
131
|
+
_forcePending: match2._forcePending,
|
|
132
|
+
_displayPending: match2._displayPending
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
structuralSharing: true
|
|
137
|
+
});
|
|
138
|
+
const route = router.routesById[routeId];
|
|
139
|
+
const out = React.useMemo(() => {
|
|
140
|
+
const Comp = route.options.component ?? router.options.defaultComponent;
|
|
141
|
+
if (Comp) {
|
|
142
|
+
return /* @__PURE__ */ jsx(Comp, {}, key);
|
|
143
|
+
}
|
|
144
|
+
return /* @__PURE__ */ jsx(Outlet, {});
|
|
145
|
+
}, [key, route.options.component, router.options.defaultComponent]);
|
|
146
|
+
if (match._displayPending) {
|
|
147
|
+
throw router.getMatch(match.id)?._nonReactive.displayPendingPromise;
|
|
148
|
+
}
|
|
149
|
+
if (match._forcePending) {
|
|
150
|
+
throw router.getMatch(match.id)?._nonReactive.minPendingPromise;
|
|
151
|
+
}
|
|
152
|
+
if (match.status === "pending") {
|
|
153
|
+
const pendingMinMs = route.options.pendingMinMs ?? router.options.defaultPendingMinMs;
|
|
154
|
+
if (pendingMinMs) {
|
|
155
|
+
const routerMatch = router.getMatch(match.id);
|
|
156
|
+
if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {
|
|
157
|
+
if (!(isServer ?? router.isServer)) {
|
|
158
|
+
const minPendingPromise = createControlledPromise();
|
|
159
|
+
routerMatch._nonReactive.minPendingPromise = minPendingPromise;
|
|
160
|
+
setTimeout(() => {
|
|
161
|
+
minPendingPromise.resolve();
|
|
162
|
+
routerMatch._nonReactive.minPendingPromise = void 0;
|
|
163
|
+
}, pendingMinMs);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
throw router.getMatch(match.id)?._nonReactive.loadPromise;
|
|
168
|
+
}
|
|
169
|
+
if (match.status === "notFound") {
|
|
170
|
+
invariant(isNotFound(match.error), "Expected a notFound error");
|
|
171
|
+
return renderRouteNotFound(router, route, match.error);
|
|
172
|
+
}
|
|
173
|
+
if (match.status === "redirected") {
|
|
174
|
+
invariant(isRedirect(match.error), "Expected a redirect error");
|
|
175
|
+
throw router.getMatch(match.id)?._nonReactive.loadPromise;
|
|
176
|
+
}
|
|
177
|
+
if (match.status === "error") {
|
|
178
|
+
if (isServer ?? router.isServer) {
|
|
179
|
+
const RouteErrorComponent = (route.options.errorComponent ?? router.options.defaultErrorComponent) || ErrorComponent;
|
|
180
|
+
return /* @__PURE__ */ jsx(
|
|
181
|
+
RouteErrorComponent,
|
|
182
|
+
{
|
|
183
|
+
error: match.error,
|
|
184
|
+
reset: void 0,
|
|
185
|
+
info: {
|
|
186
|
+
componentStack: ""
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
throw match.error;
|
|
192
|
+
}
|
|
193
|
+
return out;
|
|
194
|
+
});
|
|
195
|
+
const Outlet = React.memo(function OutletImpl() {
|
|
196
|
+
const router = useRouter();
|
|
197
|
+
const matchId = React.useContext(matchContext);
|
|
198
|
+
const routeId = useRouterState({
|
|
199
|
+
select: (s) => s.matches.find((d) => d.id === matchId)?.routeId
|
|
200
|
+
});
|
|
201
|
+
const route = router.routesById[routeId];
|
|
202
|
+
const parentGlobalNotFound = useRouterState({
|
|
203
|
+
select: (s) => {
|
|
204
|
+
const matches = s.matches;
|
|
205
|
+
const parentMatch = matches.find((d) => d.id === matchId);
|
|
206
|
+
invariant(
|
|
207
|
+
parentMatch,
|
|
208
|
+
`Could not find parent match for matchId "${matchId}"`
|
|
209
|
+
);
|
|
210
|
+
return parentMatch.globalNotFound;
|
|
211
|
+
}
|
|
212
|
+
});
|
|
213
|
+
const childMatchId = useRouterState({
|
|
214
|
+
select: (s) => {
|
|
215
|
+
const matches = s.matches;
|
|
216
|
+
const index = matches.findIndex((d) => d.id === matchId);
|
|
217
|
+
return matches[index + 1]?.id;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
const pendingElement = router.options.defaultPendingComponent ? /* @__PURE__ */ jsx(router.options.defaultPendingComponent, {}) : null;
|
|
221
|
+
if (parentGlobalNotFound) {
|
|
222
|
+
return renderRouteNotFound(router, route, void 0);
|
|
223
|
+
}
|
|
224
|
+
if (!childMatchId) {
|
|
225
|
+
return null;
|
|
226
|
+
}
|
|
227
|
+
const nextMatch = /* @__PURE__ */ jsx(Match, { matchId: childMatchId });
|
|
228
|
+
if (routeId === rootRouteId) {
|
|
229
|
+
return /* @__PURE__ */ jsx(React.Suspense, { fallback: pendingElement, children: nextMatch });
|
|
230
|
+
}
|
|
231
|
+
return nextMatch;
|
|
232
|
+
});
|
|
233
|
+
export {
|
|
234
|
+
Match,
|
|
235
|
+
MatchInner,
|
|
236
|
+
Outlet
|
|
237
|
+
};
|
|
238
|
+
//# sourceMappingURL=Match.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Match.js","sources":["../../src/Match.tsx"],"sourcesContent":["import * as React from 'react'\nimport invariant from 'tiny-invariant'\nimport warning from 'tiny-warning'\nimport {\n createControlledPromise,\n getLocationChangeInfo,\n isNotFound,\n isRedirect,\n rootRouteId,\n} from '@tanstack/router-core'\nimport { isServer } from '@tanstack/router-core/isServer'\nimport { CatchBoundary, ErrorComponent } from './CatchBoundary'\nimport { useRouterState } from './useRouterState'\nimport { useRouter } from './useRouter'\nimport { CatchNotFound } from './not-found'\nimport { matchContext } from './matchContext'\nimport { SafeFragment } from './SafeFragment'\nimport { renderRouteNotFound } from './renderRouteNotFound'\nimport { ScrollRestoration } from './scroll-restoration'\nimport { ClientOnly } from './ClientOnly'\nimport type {\n AnyRoute,\n ParsedLocation,\n RootRouteOptions,\n} from '@tanstack/router-core'\n\nexport const Match = React.memo(function MatchImpl({\n matchId,\n}: {\n matchId: string\n}) {\n const router = useRouter()\n const matchState = useRouterState({\n select: (s) => {\n const matchIndex = s.matches.findIndex((d) => d.id === matchId)\n const match = s.matches[matchIndex]\n invariant(\n match,\n `Could not find match for matchId \"${matchId}\". Please file an issue!`,\n )\n return {\n routeId: match.routeId,\n ssr: match.ssr,\n _displayPending: match._displayPending,\n resetKey: s.loadedAt,\n parentRouteId: s.matches[matchIndex - 1]?.routeId as string,\n }\n },\n structuralSharing: true as any,\n })\n\n const route: AnyRoute = router.routesById[matchState.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 resolvedNoSsr =\n matchState.ssr === false || matchState.ssr === 'data-only'\n const ResolvedSuspenseBoundary =\n // If we're on the root route, allow forcefully wrapping in suspense\n (!route.isRoot || route.options.wrapInSuspense || resolvedNoSsr) &&\n (route.options.wrapInSuspense ??\n PendingComponent ??\n ((route.options.errorComponent as any)?.preload || resolvedNoSsr))\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 ShellComponent = route.isRoot\n ? ((route.options as RootRouteOptions).shellComponent ?? SafeFragment)\n : SafeFragment\n return (\n <ShellComponent>\n <matchContext.Provider value={matchId}>\n <ResolvedSuspenseBoundary fallback={pendingElement}>\n <ResolvedCatchBoundary\n getResetKey={() => matchState.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 !== matchState.routeId) ||\n (!error.routeId && !route.isRoot)\n )\n throw error\n\n return React.createElement(routeNotFoundComponent, error as any)\n }}\n >\n {resolvedNoSsr || matchState._displayPending ? (\n <ClientOnly fallback={pendingElement}>\n <MatchInner matchId={matchId} />\n </ClientOnly>\n ) : (\n <MatchInner matchId={matchId} />\n )}\n </ResolvedNotFoundBoundary>\n </ResolvedCatchBoundary>\n </ResolvedSuspenseBoundary>\n </matchContext.Provider>\n {matchState.parentRouteId === rootRouteId &&\n router.options.scrollRestoration ? (\n <>\n <OnRendered />\n <ScrollRestoration />\n </>\n ) : null}\n </ShellComponent>\n )\n})\n\n// On Rendered can't happen above the root layout because it actually\n// renders a dummy dom element to track the rendered state of the app.\n// We render a script tag with a key that changes based on the current\n// location state.__TSR_key. Also, because it's below the root layout, it\n// allows us to fire onRendered events even after a hydration mismatch\n// error that occurred above the root layout (like bad head/link tags,\n// which is common).\nfunction OnRendered() {\n const router = useRouter()\n\n const prevLocationRef = React.useRef<undefined | ParsedLocation<{}>>(\n undefined,\n )\n\n return (\n <script\n key={router.latestLocation.state.__TSR_key}\n suppressHydrationWarning\n ref={(el) => {\n if (\n el &&\n (prevLocationRef.current === undefined ||\n prevLocationRef.current.href !== router.latestLocation.href)\n ) {\n router.emit({\n type: 'onRendered',\n ...getLocationChangeInfo(router.state),\n })\n prevLocationRef.current = router.latestLocation\n }\n }}\n />\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, key, routeId } = useRouterState({\n select: (s) => {\n const match = s.matches.find((d) => d.id === matchId)!\n const routeId = match.routeId as string\n\n const remountFn =\n (router.routesById[routeId] as AnyRoute).options.remountDeps ??\n router.options.defaultRemountDeps\n const remountDeps = remountFn?.({\n routeId,\n loaderDeps: match.loaderDeps,\n params: match._strictParams,\n search: match._strictSearch,\n })\n const key = remountDeps ? JSON.stringify(remountDeps) : undefined\n\n return {\n key,\n routeId,\n match: {\n id: match.id,\n status: match.status,\n error: match.error,\n invalid: match.invalid,\n _forcePending: match._forcePending,\n _displayPending: match._displayPending,\n },\n }\n },\n structuralSharing: true as any,\n })\n\n const route = router.routesById[routeId] as AnyRoute\n\n const out = React.useMemo(() => {\n const Comp = route.options.component ?? router.options.defaultComponent\n if (Comp) {\n return <Comp key={key} />\n }\n return <Outlet />\n }, [key, route.options.component, router.options.defaultComponent])\n\n if (match._displayPending) {\n throw router.getMatch(match.id)?._nonReactive.displayPendingPromise\n }\n\n if (match._forcePending) {\n throw router.getMatch(match.id)?._nonReactive.minPendingPromise\n }\n\n // see also hydrate() in packages/router-core/src/ssr/ssr-client.ts\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 if (pendingMinMs) {\n const routerMatch = router.getMatch(match.id)\n if (routerMatch && !routerMatch._nonReactive.minPendingPromise) {\n // Create a promise that will resolve after the minPendingMs\n if (!(isServer ?? router.isServer)) {\n const minPendingPromise = createControlledPromise<void>()\n\n routerMatch._nonReactive.minPendingPromise = minPendingPromise\n\n setTimeout(() => {\n minPendingPromise.resolve()\n // We've handled the minPendingPromise, so we can delete it\n routerMatch._nonReactive.minPendingPromise = undefined\n }, pendingMinMs)\n }\n }\n }\n throw router.getMatch(match.id)?._nonReactive.loadPromise\n }\n\n if (match.status === 'notFound') {\n invariant(isNotFound(match.error), 'Expected a notFound error')\n return renderRouteNotFound(router, route, match.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 router.getMatch(match.id)?._nonReactive.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 (isServer ?? router.isServer) {\n const RouteErrorComponent =\n (route.options.errorComponent ??\n router.options.defaultErrorComponent) ||\n ErrorComponent\n return (\n <RouteErrorComponent\n error={match.error as any}\n reset={undefined as any}\n info={{\n componentStack: '',\n }}\n />\n )\n }\n\n throw match.error\n }\n\n return out\n})\n\n/**\n * Render the next child match in the route tree. Typically used inside\n * a route component to render nested routes.\n *\n * @link https://tanstack.com/router/latest/docs/framework/react/api/router/outletComponent\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 parentMatch.globalNotFound\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 const pendingElement = router.options.defaultPendingComponent ? (\n <router.options.defaultPendingComponent />\n ) : null\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 if (routeId === rootRouteId) {\n return (\n <React.Suspense fallback={pendingElement}>{nextMatch}</React.Suspense>\n )\n }\n\n return nextMatch\n})\n"],"names":["match","routeId","key"],"mappings":";;;;;;;;;;;;;;;AA0BO,MAAM,QAAQ,MAAM,KAAK,SAAS,UAAU;AAAA,EACjD;AACF,GAEG;AACD,QAAM,SAAS,UAAA;AACf,QAAM,aAAa,eAAe;AAAA,IAChC,QAAQ,CAAC,MAAM;AACb,YAAM,aAAa,EAAE,QAAQ,UAAU,CAAC,MAAM,EAAE,OAAO,OAAO;AAC9D,YAAM,QAAQ,EAAE,QAAQ,UAAU;AAClC;AAAA,QACE;AAAA,QACA,qCAAqC,OAAO;AAAA,MAAA;AAE9C,aAAO;AAAA,QACL,SAAS,MAAM;AAAA,QACf,KAAK,MAAM;AAAA,QACX,iBAAiB,MAAM;AAAA,QACvB,UAAU,EAAE;AAAA,QACZ,eAAe,EAAE,QAAQ,aAAa,CAAC,GAAG;AAAA,MAAA;AAAA,IAE9C;AAAA,IACA,mBAAmB;AAAA,EAAA,CACpB;AAED,QAAM,QAAkB,OAAO,WAAW,WAAW,OAAO;AAE5D,QAAM,mBACJ,MAAM,QAAQ,oBAAoB,OAAO,QAAQ;AAEnD,QAAM,iBAAiB,mBAAmB,oBAAC,kBAAA,CAAA,CAAiB,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MAAM;AACb,YAAM,UAAU,EAAE;AAClB,YAAM,QAAQ,QAAQ,UAAU,CAAC,MAAM,EAAE,OAAO,OAAO;AACvD,aAAO,QAAQ,QAAQ,CAAC,GAAG;AAAA,IAC7B;AAAA,EAAA,CACD;AAED,QAAM,iBAAiB,OAAO,QAAQ,8CACnC,OAAO,QAAQ,yBAAf,CAAA,CAAuC,IACtC;AAEJ,MAAI,sBAAsB;AACxB,WAAO,oBAAoB,QAAQ,OAAO,MAAS;AAAA,EACrD;AAEA,MAAI,CAAC,cAAc;AACjB,WAAO;AAAA,EACT;AAEA,QAAM,YAAY,oBAAC,OAAA,EAAM,SAAS,aAAA,CAAc;AAEhD,MAAI,YAAY,aAAa;AAC3B,+BACG,MAAM,UAAN,EAAe,UAAU,gBAAiB,UAAA,WAAU;AAAA,EAEzD;AAEA,SAAO;AACT,CAAC;"}
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { StructuralSharingOption, ValidateSelected } from './structuralSharing.js';
|
|
2
|
+
import { AnyRouter, DeepPartial, Expand, MakeOptionalPathParams, MakeOptionalSearchParams, MakeRouteMatchUnion, MaskOptions, MatchRouteOptions, NoInfer, RegisteredRouter, ResolveRelativePath, ResolveRoute, RouteByPath, ToSubOptionsProps } from '@tanstack/router-core';
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
declare module '@tanstack/router-core' {
|
|
5
|
+
interface RouteMatchExtensions {
|
|
6
|
+
meta?: Array<React.JSX.IntrinsicElements['meta'] | undefined>;
|
|
7
|
+
links?: Array<React.JSX.IntrinsicElements['link'] | undefined>;
|
|
8
|
+
scripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>;
|
|
9
|
+
styles?: Array<React.JSX.IntrinsicElements['style'] | undefined>;
|
|
10
|
+
headScripts?: Array<React.JSX.IntrinsicElements['script'] | undefined>;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Internal component that renders the router's active match tree with
|
|
15
|
+
* suspense, error, and not-found boundaries. Rendered by `RouterProvider`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function Matches(): import("react/jsx-runtime").JSX.Element;
|
|
18
|
+
export type UseMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = ToSubOptionsProps<TRouter, TFrom, TTo> & DeepPartial<MakeOptionalSearchParams<TRouter, TFrom, TTo>> & DeepPartial<MakeOptionalPathParams<TRouter, TFrom, TTo>> & MaskOptions<TRouter, TMaskFrom, TMaskTo> & MatchRouteOptions;
|
|
19
|
+
/**
|
|
20
|
+
* Create a matcher function for testing locations against route definitions.
|
|
21
|
+
*
|
|
22
|
+
* The returned function accepts standard navigation options (`to`, `params`,
|
|
23
|
+
* `search`, etc.) and returns either `false` (no match) or the matched params
|
|
24
|
+
* object when the route matches the current or pending location.
|
|
25
|
+
*
|
|
26
|
+
* Useful for conditional rendering and active UI states.
|
|
27
|
+
*
|
|
28
|
+
* @returns A `matchRoute(options)` function that returns `false` or params.
|
|
29
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchRouteHook
|
|
30
|
+
*/
|
|
31
|
+
export declare function useMatchRoute<TRouter extends AnyRouter = RegisteredRouter>(): <const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = "">(opts: UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>) => false | Expand<ResolveRoute<TRouter, TFrom, TTo>["types"]["allParams"]>;
|
|
32
|
+
export type MakeMatchRouteOptions<TRouter extends AnyRouter = RegisteredRouter, TFrom extends string = string, TTo extends string | undefined = undefined, TMaskFrom extends string = TFrom, TMaskTo extends string = ''> = UseMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo> & {
|
|
33
|
+
children?: ((params?: RouteByPath<TRouter['routeTree'], ResolveRelativePath<TFrom, NoInfer<TTo>>>['types']['allParams']) => React.ReactNode) | React.ReactNode;
|
|
34
|
+
};
|
|
35
|
+
/**
|
|
36
|
+
* Component that conditionally renders its children based on whether a route
|
|
37
|
+
* matches the provided `from`/`to` options. If `children` is a function, it
|
|
38
|
+
* receives the matched params object.
|
|
39
|
+
*
|
|
40
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/matchRouteComponent
|
|
41
|
+
*/
|
|
42
|
+
export declare function MatchRoute<TRouter extends AnyRouter = RegisteredRouter, const TFrom extends string = string, const TTo extends string | undefined = undefined, const TMaskFrom extends string = TFrom, const TMaskTo extends string = ''>(props: MakeMatchRouteOptions<TRouter, TFrom, TTo, TMaskFrom, TMaskTo>): any;
|
|
43
|
+
export interface UseMatchesBaseOptions<TRouter extends AnyRouter, TSelected, TStructuralSharing> {
|
|
44
|
+
select?: (matches: Array<MakeRouteMatchUnion<TRouter>>) => ValidateSelected<TRouter, TSelected, TStructuralSharing>;
|
|
45
|
+
}
|
|
46
|
+
export type UseMatchesResult<TRouter extends AnyRouter, TSelected> = unknown extends TSelected ? Array<MakeRouteMatchUnion<TRouter>> : TSelected;
|
|
47
|
+
export declare function useMatches<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>): UseMatchesResult<TRouter, TSelected>;
|
|
48
|
+
/**
|
|
49
|
+
* Read the full array of active route matches or select a derived subset.
|
|
50
|
+
*
|
|
51
|
+
* Useful for debugging, breadcrumbs, or aggregating metadata across matches.
|
|
52
|
+
*
|
|
53
|
+
* @returns The array of matches (or the selected value).
|
|
54
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook
|
|
55
|
+
*/
|
|
56
|
+
/**
|
|
57
|
+
* Read the full array of active route matches or select a derived subset.
|
|
58
|
+
*
|
|
59
|
+
* Useful for debugging, breadcrumbs, or aggregating metadata across matches.
|
|
60
|
+
*
|
|
61
|
+
* @link https://tanstack.com/router/latest/docs/framework/react/api/router/useMatchesHook
|
|
62
|
+
*/
|
|
63
|
+
export declare function useParentMatches<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>): UseMatchesResult<TRouter, TSelected>;
|
|
64
|
+
/**
|
|
65
|
+
* Read the array of active route matches that are children of the current
|
|
66
|
+
* match (or selected parent) in the match tree.
|
|
67
|
+
*/
|
|
68
|
+
export declare function useChildMatches<TRouter extends AnyRouter = RegisteredRouter, TSelected = unknown, TStructuralSharing extends boolean = boolean>(opts?: UseMatchesBaseOptions<TRouter, TSelected, TStructuralSharing> & StructuralSharingOption<TRouter, TSelected, TStructuralSharing>): UseMatchesResult<TRouter, TSelected>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
2
|
+
import * as React from "react";
|
|
3
|
+
import warning from "tiny-warning";
|
|
4
|
+
import { rootRouteId } from "@tanstack/router-core";
|
|
5
|
+
import { isServer } from "@tanstack/router-core/isServer";
|
|
6
|
+
import { CatchBoundary, ErrorComponent } from "./CatchBoundary.js";
|
|
7
|
+
import { useRouterState } from "./useRouterState.js";
|
|
8
|
+
import { useRouter } from "./useRouter.js";
|
|
9
|
+
import { Transitioner } from "./Transitioner.js";
|
|
10
|
+
import { matchContext } from "./matchContext.js";
|
|
11
|
+
import { Match } from "./Match.js";
|
|
12
|
+
import { SafeFragment } from "./SafeFragment.js";
|
|
13
|
+
function Matches() {
|
|
14
|
+
const router = useRouter();
|
|
15
|
+
const rootRoute = router.routesById[rootRouteId];
|
|
16
|
+
const PendingComponent = rootRoute.options.pendingComponent ?? router.options.defaultPendingComponent;
|
|
17
|
+
const pendingElement = PendingComponent ? /* @__PURE__ */ jsx(PendingComponent, {}) : null;
|
|
18
|
+
const ResolvedSuspense = (isServer ?? router.isServer) || typeof document !== "undefined" && router.ssr ? SafeFragment : React.Suspense;
|
|
19
|
+
const inner = /* @__PURE__ */ jsxs(ResolvedSuspense, { fallback: pendingElement, children: [
|
|
20
|
+
!(isServer ?? router.isServer) && /* @__PURE__ */ jsx(Transitioner, {}),
|
|
21
|
+
/* @__PURE__ */ jsx(MatchesInner, {})
|
|
22
|
+
] });
|
|
23
|
+
return router.options.InnerWrap ? /* @__PURE__ */ jsx(router.options.InnerWrap, { children: inner }) : inner;
|
|
24
|
+
}
|
|
25
|
+
function MatchesInner() {
|
|
26
|
+
const router = useRouter();
|
|
27
|
+
const matchId = useRouterState({
|
|
28
|
+
select: (s) => {
|
|
29
|
+
return s.matches[0]?.id;
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
const resetKey = useRouterState({
|
|
33
|
+
select: (s) => s.loadedAt
|
|
34
|
+
});
|
|
35
|
+
const matchComponent = matchId ? /* @__PURE__ */ jsx(Match, { matchId }) : null;
|
|
36
|
+
return /* @__PURE__ */ jsx(matchContext.Provider, { value: matchId, children: router.options.disableGlobalCatchBoundary ? matchComponent : /* @__PURE__ */ jsx(
|
|
37
|
+
CatchBoundary,
|
|
38
|
+
{
|
|
39
|
+
getResetKey: () => resetKey,
|
|
40
|
+
errorComponent: ErrorComponent,
|
|
41
|
+
onCatch: process.env.NODE_ENV !== "production" ? (error) => {
|
|
42
|
+
warning(
|
|
43
|
+
false,
|
|
44
|
+
`The following error wasn't caught by any route! At the very least, consider setting an 'errorComponent' in your RootRoute!`
|
|
45
|
+
);
|
|
46
|
+
warning(false, error.message || error.toString());
|
|
47
|
+
} : void 0,
|
|
48
|
+
children: matchComponent
|
|
49
|
+
}
|
|
50
|
+
) });
|
|
51
|
+
}
|
|
52
|
+
function useMatchRoute() {
|
|
53
|
+
const router = useRouter();
|
|
54
|
+
useRouterState({
|
|
55
|
+
select: (s) => [s.location.href, s.resolvedLocation?.href, s.status],
|
|
56
|
+
structuralSharing: true
|
|
57
|
+
});
|
|
58
|
+
return React.useCallback(
|
|
59
|
+
(opts) => {
|
|
60
|
+
const { pending, caseSensitive, fuzzy, includeSearch, ...rest } = opts;
|
|
61
|
+
return router.matchRoute(rest, {
|
|
62
|
+
pending,
|
|
63
|
+
caseSensitive,
|
|
64
|
+
fuzzy,
|
|
65
|
+
includeSearch
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
[router]
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
function MatchRoute(props) {
|
|
72
|
+
const matchRoute = useMatchRoute();
|
|
73
|
+
const params = matchRoute(props);
|
|
74
|
+
if (typeof props.children === "function") {
|
|
75
|
+
return props.children(params);
|
|
76
|
+
}
|
|
77
|
+
return params ? props.children : null;
|
|
78
|
+
}
|
|
79
|
+
function useMatches(opts) {
|
|
80
|
+
return useRouterState({
|
|
81
|
+
select: (state) => {
|
|
82
|
+
const matches = state.matches;
|
|
83
|
+
return opts?.select ? opts.select(matches) : matches;
|
|
84
|
+
},
|
|
85
|
+
structuralSharing: opts?.structuralSharing
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function useParentMatches(opts) {
|
|
89
|
+
const contextMatchId = React.useContext(matchContext);
|
|
90
|
+
return useMatches({
|
|
91
|
+
select: (matches) => {
|
|
92
|
+
matches = matches.slice(
|
|
93
|
+
0,
|
|
94
|
+
matches.findIndex((d) => d.id === contextMatchId)
|
|
95
|
+
);
|
|
96
|
+
return opts?.select ? opts.select(matches) : matches;
|
|
97
|
+
},
|
|
98
|
+
structuralSharing: opts?.structuralSharing
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
function useChildMatches(opts) {
|
|
102
|
+
const contextMatchId = React.useContext(matchContext);
|
|
103
|
+
return useMatches({
|
|
104
|
+
select: (matches) => {
|
|
105
|
+
matches = matches.slice(
|
|
106
|
+
matches.findIndex((d) => d.id === contextMatchId) + 1
|
|
107
|
+
);
|
|
108
|
+
return opts?.select ? opts.select(matches) : matches;
|
|
109
|
+
},
|
|
110
|
+
structuralSharing: opts?.structuralSharing
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
export {
|
|
114
|
+
MatchRoute,
|
|
115
|
+
Matches,
|
|
116
|
+
useChildMatches,
|
|
117
|
+
useMatchRoute,
|
|
118
|
+
useMatches,
|
|
119
|
+
useParentMatches
|
|
120
|
+
};
|
|
121
|
+
//# sourceMappingURL=Matches.js.map
|