How do i make navbar disappear in some pages

Viewed 30
function App() {
  return (
    <BrowserRouter>
      <Navlinks />

      <Routes>
        <Route
          render={({ location }) =>
            location.pathname !== "/" ? <Navlinks /> : true
          }
        />
        <Route path="SignUp" element={<Signup />} />
        <Route path="/" element={<Home></Home>} />
        <Route path="Lorem" element={<Lorem />} />
        <Route path="AboutUs" element={<AboutUs />} />
      </Routes>
    </BrowserRouter>
  );
}

/* <Route index element={<Home funcNav={setShowNav} />} />; */

// props.funcNav(false);

export default App;
2 Answers

You can add an if statement, and use the location path function, if the pathname is "bla" for example, you can print the navbar, or add a div containing the navbar, but with a hidden visibility.


you can use to get the path.
import { useLocation } from "react-router-dom";
let location = useLocation();

After that, you just have to check where you want to display it and where you don't.

you can create an array like this.

['path1', 'path2', 'path3'].includes(location.pathname) && ...
Related