function App() {
return (
<BrowserRouter>
<UserProvider>
<div className="App">
<Navbar />
<Hnavbar />
<Routes>
<Route path="/" element={<LandingPage />}></Route>
<Route path="/analytics" element={<Analytics />}></Route>
<Route path="/home" element={<Home />}></Route>
<Route path="/signup" element={<SignUp />}></Route>
<Route path="/signin" element={<SignIn />}></Route>
<Route path="/nearby-hospitals" element={<Hospitals />}></Route>
<Route path="/subscribe" element={<Subscribe />}></Route>
</Routes>
<ToastContainer theme="light" />
</div>
</UserProvider>
</BrowserRouter>
);
}
export default App;
This is my main App.js
code of React. Now I want that in signup and signin pages, Navbar
should not be visible. So to do that?
function App() {
const location = useLocation();
const isAuthPage = location.pathname === "/signin" || location.pathname === "/signup";
return (
<UserProvider>
<BrowserRouter>
<div className="App">
{!isAuthPage && <Navbar />}
<Hnavbar />
<Routes>
<Route path="/" element={<LandingPage />} />
<Route path="/analytics" element={<Analytics />} />
<Route path="/home" element={<Home />} />
<Route path="/signup" element={<SignUp />} />
<Route path="/signin" element={<SignIn />} />
{/* Rest of the routes */}
{/* ... */}
</Routes>
<ToastContainer theme="light" />
</div>
</BrowserRouter>
</UserProvider>
);
}
I tried this with the help of uselocation
to get current url path but it gave me error history.ts:480 Uncaught Error: useLocation() may be used only in the context of a <Router> component.