import { BrowserRouter as Router, Routes, Route, Link} from 'react-router-dom';
import { Home } from '../Pages/Home';
import { Login } from '../Pages/Login';
import { Register } from '../Pages/Register';
function App() {
return (
<Router>
<Navbar/>
<Routes>
<Route path='/home' element={ <Home />}></Route>
<Route path='/login' element={ <Login />}></Route>
<Route path='/register' element={ <Register />}></Route>
<Route path="*" element={ <h1>Page Not Found</h1>}></Route>
</Routes>
</Router>
);
}
export default App;
I can’t think a logic how to make it disappear when it is directed in page not found.
2
Answers
Wich version are you using? I think you can use the
useLocation()
function. Something like this:I have used this a long time ago. Maybe still work
First, we should change the URL of the NotFoundPage when accessing invalid address to be "/404" as the following:
After that, we can easily detect if we are in NotFoundPage to remove the NavBar