Skip to content

Instantly share code, notes, and snippets.

@SahanAmarsha
Last active March 17, 2022 09:59
Show Gist options
  • Save SahanAmarsha/44b1164d7f999c276663634c6b984430 to your computer and use it in GitHub Desktop.
Save SahanAmarsha/44b1164d7f999c276663634c6b984430 to your computer and use it in GitHub Desktop.
App.tsx Iterating Through Routes
// src/App.tsx
import React from "react";
import { Box, CssBaseline, ThemeProvider } from "@mui/material";
import { createTheme } from "@mui/material/styles";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";
import { routes as appRoutes } from "./routes";
function App() {
// define theme
const theme = createTheme({
palette: {
primary: {
light: "#63b8ff",
main: "#0989e3",
dark: "#005db0",
contrastText: "#000",
},
secondary: {
main: "#4db6ac",
light: "#82e9de",
dark: "#00867d",
contrastText: "#000",
},
},
});
return (
<ThemeProvider theme={theme}>
<CssBaseline />
<Box height="100vh" display="flex" flexDirection="column">
<Router>
<Routes>
{appRoutes.map((route) => (
<Route
key={route.key}
path={route.path}
element={<route.component />}
/>
))}
</Routes>
</Router>
</Box>
</ThemeProvider>
);
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment