gemma: generate apps/web/src/App.tsx
This commit is contained in:
parent
39e974d7a5
commit
547e04531d
70
apps/web/src/App.tsx
Normal file
70
apps/web/src/App.tsx
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
import { createRootRoute, createRoute, createRouter, RouterProvider, Outlet, redirect } from "@tanstack/react-router"
|
||||||
|
import Dashboard from "./pages/Dashboard"
|
||||||
|
import Login from "./pages/Login"
|
||||||
|
import TimeEntries from "./pages/TimeEntries"
|
||||||
|
import { api } from "./lib/api"
|
||||||
|
|
||||||
|
const rootRoute = createRootRoute({
|
||||||
|
component: () => (
|
||||||
|
<div className="min-h-screen bg-slate-50">
|
||||||
|
<Outlet />
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
const loginRoute = createRoute({
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
path: "/login",
|
||||||
|
component: Login
|
||||||
|
})
|
||||||
|
|
||||||
|
const indexRoute = createRoute({
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
path: "/",
|
||||||
|
beforeLoad: async () => {
|
||||||
|
try {
|
||||||
|
await api.getMe()
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.status === 401) {
|
||||||
|
throw redirect({ to: "/login" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
component: Dashboard
|
||||||
|
})
|
||||||
|
|
||||||
|
const timeEntriesRoute = createRoute({
|
||||||
|
getParentRoute: () => rootRoute,
|
||||||
|
path: "/time-entries",
|
||||||
|
beforeLoad: async () => {
|
||||||
|
try {
|
||||||
|
await api.getMe()
|
||||||
|
} catch (error: any) {
|
||||||
|
if (error.status === 401) {
|
||||||
|
throw redirect({ to: "/login" })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
component: TimeEntries
|
||||||
|
})
|
||||||
|
|
||||||
|
const routeTree = rootRoute.addChildren([
|
||||||
|
indexRoute,
|
||||||
|
loginRoute,
|
||||||
|
timeEntriesRoute
|
||||||
|
])
|
||||||
|
|
||||||
|
const router = createRouter({
|
||||||
|
routeTree,
|
||||||
|
defaultPreload: "intent"
|
||||||
|
})
|
||||||
|
|
||||||
|
declare module "@tanstack/react-router" {
|
||||||
|
interface Register {
|
||||||
|
router: typeof router
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function App() {
|
||||||
|
return <RouterProvider router={router} />
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user