createBrowserRouter
import { RouterProvider, createBrowserRouter } from "react-router-dom";
import Layout from "./components/Layout.tsx";
import Home from "./routes/Home.tsx";
import Profile from "./routes/Profile.tsx";
import { Login } from "./routes/Login.tsx";
import { CreateAccount } from "./routes/create-account.tsx";
const router = createBrowserRouter([
{
path: "/",
element: (
<ProtectedRoute>
<Layout />
</ProtectedRoute>
),
children: [
{
path: "",
element: <Home />,
},
{
path: "profile",
element: <Profile />,
},
],
},
{
path: "/login",
element: <Login />,
},
{
path: "/create-account",
element: <CreateAccount />,
},
]);
function App() {
return (
<>
<RouterProvider router={router} />
</>
);
}
export default App;
outlet
import { Outlet } from "react-router-dom";
const Layout = () => {
return (
<>
<h2>layout</h2>
<Outlet />
</>
);
};
export default Layout;
GlobalStyles
import { createGlobalStyle } from "styled-components";
import reset from "styled-reset";
const GlobalStyles = createGlobalStyle`
${reset};
* {
box-sizing: border-box;
}
body {
background-color: black;
color: white;
font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, 'Open Sans', 'Helvetica Neue', sans-serif;
}
`;
function App() {
return (
<>
<GlobalStyles />
<RouterProvider router={router} />
</>
);
}
export default App;