base layout
This commit is contained in:
@@ -8,10 +8,19 @@ import {
|
|||||||
Toolbar,
|
Toolbar,
|
||||||
Typography,
|
Typography,
|
||||||
} from "@mui/material";
|
} from "@mui/material";
|
||||||
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
import type { FileRouteTypes } from "../routeTree.gen";
|
||||||
import { RouterButton } from "./RouterButton";
|
import { RouterButton } from "./RouterButton";
|
||||||
|
|
||||||
const pages = ["Products", "Pricing", "Blog"];
|
type ValidRoutes = FileRouteTypes["to"];
|
||||||
|
|
||||||
|
interface Page {
|
||||||
|
title: string;
|
||||||
|
to: ValidRoutes;
|
||||||
|
}
|
||||||
|
|
||||||
|
const pages: Page[] = [{ title: "Announcements", to: "/" }];
|
||||||
|
|
||||||
export default function DashboardLayout({
|
export default function DashboardLayout({
|
||||||
children,
|
children,
|
||||||
@@ -28,16 +37,10 @@ export default function DashboardLayout({
|
|||||||
setAnchorElNav(null);
|
setAnchorElNav(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box
|
<Box>
|
||||||
sx={{
|
|
||||||
position: "relative",
|
|
||||||
display: "flex",
|
|
||||||
overflow: "hidden",
|
|
||||||
height: "100%",
|
|
||||||
width: "100%",
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<AppBar position="static">
|
<AppBar position="static">
|
||||||
<Toolbar>
|
<Toolbar>
|
||||||
{/* desktop */}
|
{/* desktop */}
|
||||||
@@ -78,8 +81,16 @@ export default function DashboardLayout({
|
|||||||
sx={{ display: { xs: "block", md: "none" } }}
|
sx={{ display: { xs: "block", md: "none" } }}
|
||||||
>
|
>
|
||||||
{pages.map((page) => (
|
{pages.map((page) => (
|
||||||
<MenuItem key={page} onClick={handleCloseNavMenu}>
|
<MenuItem
|
||||||
<Typography sx={{ textAlign: "center" }}>{page}</Typography>
|
key={page.to}
|
||||||
|
onClick={() => {
|
||||||
|
handleCloseNavMenu();
|
||||||
|
navigate({ to: page.to });
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Typography sx={{ textAlign: "center" }}>
|
||||||
|
{page.title}
|
||||||
|
</Typography>
|
||||||
</MenuItem>
|
</MenuItem>
|
||||||
))}
|
))}
|
||||||
</Menu>
|
</Menu>
|
||||||
@@ -96,29 +107,21 @@ export default function DashboardLayout({
|
|||||||
<Box sx={{ flexGrow: 1, display: { xs: "none", md: "flex" } }}>
|
<Box sx={{ flexGrow: 1, display: { xs: "none", md: "flex" } }}>
|
||||||
{pages.map((page) => (
|
{pages.map((page) => (
|
||||||
<RouterButton
|
<RouterButton
|
||||||
key={page}
|
key={page.to}
|
||||||
onClick={handleCloseNavMenu}
|
onClick={handleCloseNavMenu}
|
||||||
sx={{ my: 2, color: "white", display: "block" }}
|
sx={{ my: 2, color: "white", display: "block" }}
|
||||||
to="."
|
to={page.to}
|
||||||
>
|
>
|
||||||
{page}
|
{page.title}
|
||||||
</RouterButton>
|
</RouterButton>
|
||||||
))}
|
))}
|
||||||
</Box>
|
</Box>
|
||||||
</Toolbar>
|
</Toolbar>
|
||||||
</AppBar>
|
</AppBar>
|
||||||
<Box
|
|
||||||
sx={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
flex: 1,
|
|
||||||
minWidth: 0,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Toolbar sx={{ displayPrint: "none" }} />
|
|
||||||
<Box
|
<Box
|
||||||
component="main"
|
component="main"
|
||||||
sx={{
|
sx={{
|
||||||
|
m: 8,
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
flex: 1,
|
flex: 1,
|
||||||
@@ -128,6 +131,5 @@ export default function DashboardLayout({
|
|||||||
{children}
|
{children}
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
+34
-10
@@ -9,27 +9,51 @@
|
|||||||
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
|
// Additionally, you should also exclude this file from your linter and/or formatter to prevent it from being checked or modified.
|
||||||
|
|
||||||
import { Route as rootRouteImport } from './routes/__root'
|
import { Route as rootRouteImport } from './routes/__root'
|
||||||
|
import { Route as IndexRouteImport } from './routes/index'
|
||||||
|
|
||||||
export interface FileRoutesByFullPath {}
|
const IndexRoute = IndexRouteImport.update({
|
||||||
export interface FileRoutesByTo {}
|
id: '/',
|
||||||
|
path: '/',
|
||||||
|
getParentRoute: () => rootRouteImport,
|
||||||
|
} as any)
|
||||||
|
|
||||||
|
export interface FileRoutesByFullPath {
|
||||||
|
'/': typeof IndexRoute
|
||||||
|
}
|
||||||
|
export interface FileRoutesByTo {
|
||||||
|
'/': typeof IndexRoute
|
||||||
|
}
|
||||||
export interface FileRoutesById {
|
export interface FileRoutesById {
|
||||||
__root__: typeof rootRouteImport
|
__root__: typeof rootRouteImport
|
||||||
|
'/': typeof IndexRoute
|
||||||
}
|
}
|
||||||
export interface FileRouteTypes {
|
export interface FileRouteTypes {
|
||||||
fileRoutesByFullPath: FileRoutesByFullPath
|
fileRoutesByFullPath: FileRoutesByFullPath
|
||||||
fullPaths: never
|
fullPaths: '/'
|
||||||
fileRoutesByTo: FileRoutesByTo
|
fileRoutesByTo: FileRoutesByTo
|
||||||
to: never
|
to: '/'
|
||||||
id: '__root__'
|
id: '__root__' | '/'
|
||||||
fileRoutesById: FileRoutesById
|
fileRoutesById: FileRoutesById
|
||||||
}
|
}
|
||||||
export interface RootRouteChildren {}
|
export interface RootRouteChildren {
|
||||||
|
IndexRoute: typeof IndexRoute
|
||||||
declare module '@tanstack/react-router' {
|
|
||||||
interface FileRoutesByPath {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const rootRouteChildren: RootRouteChildren = {}
|
declare module '@tanstack/react-router' {
|
||||||
|
interface FileRoutesByPath {
|
||||||
|
'/': {
|
||||||
|
id: '/'
|
||||||
|
path: '/'
|
||||||
|
fullPath: '/'
|
||||||
|
preLoaderRoute: typeof IndexRouteImport
|
||||||
|
parentRoute: typeof rootRouteImport
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const rootRouteChildren: RootRouteChildren = {
|
||||||
|
IndexRoute: IndexRoute,
|
||||||
|
}
|
||||||
export const routeTree = rootRouteImport
|
export const routeTree = rootRouteImport
|
||||||
._addFileChildren(rootRouteChildren)
|
._addFileChildren(rootRouteChildren)
|
||||||
._addFileTypes<FileRouteTypes>()
|
._addFileTypes<FileRouteTypes>()
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { createFileRoute } from "@tanstack/react-router";
|
||||||
|
|
||||||
|
export const Route = createFileRoute("/")({
|
||||||
|
component: RouteComponent,
|
||||||
|
});
|
||||||
|
|
||||||
|
function RouteComponent() {
|
||||||
|
return <div>Hello "/"!</div>;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user