diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index f657013..0a4ffeb 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -1,8 +1,22 @@ import { Outlet, createRootRoute, Link } from '@tanstack/react-router'; import { TanStackRouterDevtools } from '@tanstack/react-router-devtools'; +import { getContacts } from "@/data"; + +async function fetchContacts() { + const contacts = await getContacts(); + return { contacts }; +} export const Route = createRootRoute({ - component: () => ( + loader: fetchContacts, + component: RootLayout, + notFoundComponent: NotFoundComponent, +}); + +function RootLayout() { + const { contacts } = Route.useLoaderData(); + + return ( <>
@@ -37,9 +67,8 @@ export const Route = createRootRoute({
- ), - notFoundComponent: NotFoundComponent, -}); + ); +} function NotFoundComponent() { return (