Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to add fixed navbar in react-router-dom v6.4.5

As, I’m migrating my routes from old version to v6.4.5.But is not showing me Home & Auth component. Is there any way to fix it so that i can make it working.

import { Container } from "@mui/material";
import Navbar from "./components/Navbar/Navbar";
import Home from "./components/Home/Home";
import Auth from "./components/Auth/Auth";
import { createBrowserRouter, Route, Link } from "react-router-dom";

export const App = () => {
  return (
    <Container maxWidth="lg">
      <Navbar />
    </Container>
  );
};

const router = createBrowserRouter([
  {
  
    element: <App />,
    children: [
      {
        path: "/home",
        element: <Home />,
      },
      {
        path: "/auth",
        element: <Auth />,
      },
    ],
  },
]);

export default router;

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Assuming <App> as the path "/" by default (it’s not specified in the doc), you need to remove it from your children routes:

const router = createBrowserRouter([
  {
    path: "/"
    element: <App />,
    children: [
      {
        path: "home",
        element: <Home />,
      },
      {
        path: "auth",
        element: <Auth />,
      },
    ],
  },
]);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading