← full-stack-fastapi-template / frontend/src/routes/_layout.tsx
| 1 | import { createFileRoute, Outlet, redirect } from "@tanstack/react-router" |
| 2 | |
| 3 | import { Footer } from "@/components/Common/Footer" |
| 4 | import AppSidebar from "@/components/Sidebar/AppSidebar" |
| 5 | import { |
| 6 | SidebarInset, |
| 7 | SidebarProvider, |
| 8 | SidebarTrigger, |
| 9 | } from "@/components/ui/sidebar" |
| 10 | import { isLoggedIn } from "@/hooks/useAuth" |
| 11 | |
| 12 | export const Route = createFileRoute("/_layout")({ |
| 13 | component: Layout, |
| 14 | beforeLoad: async () => { |
| 15 | if (!isLoggedIn()) { |
| 16 | throw redirect({ |
| 17 | to: "/login", |
| 18 | }) |
| 19 | } |
| 20 | }, |
| 21 | }) |
| 22 | |
| 23 | function Layout() { |
| 24 | return ( |
| 25 | <SidebarProvider> |
| 26 | <AppSidebar /> |
| 27 | <SidebarInset> |
| 28 | <header className="sticky top-0 z-10 flex h-16 shrink-0 items-center gap-2 border-b px-4"> |
| 29 | <SidebarTrigger className="-ml-1 text-muted-foreground" /> |
| 30 | </header> |
| 31 | <main className="flex-1 p-6 md:p-8"> |
| 32 | <div className="mx-auto max-w-7xl"> |
| 33 | <Outlet /> |
| 34 | </div> |
| 35 | </main> |
| 36 | <Footer /> |
| 37 | </SidebarInset> |
| 38 | </SidebarProvider> |
| 39 | ) |
| 40 | } |
| 41 | |
| 42 | export default Layout |
| 43 |