Skip to content

Instantly share code, notes, and snippets.

@Rahulhanje
Created June 16, 2024 11:59
Show Gist options
  • Save Rahulhanje/e6a847b4ce2137bb9f1e2ad7d06ece4f to your computer and use it in GitHub Desktop.
Save Rahulhanje/e6a847b4ce2137bb9f1e2ad7d06ece4f to your computer and use it in GitHub Desktop.
useNavigate()
import { BrowserRouter, Route, Routes, useNavigate } from 'react-router-dom'
import { Dashboard } from './Components/Dashboard'
import { Landing } from './Components/Landing'
function App() {
return (
<div>
<BrowserRouter>
<Appbar/>
<Routes>
<Route path="/dashboard" element={<Dashboard></Dashboard>}></Route>
<Route path='/' element={<Landing></Landing>}></Route>
</Routes>
</BrowserRouter>
</div>
)
}
function Appbar() {
const navigate = useNavigate;
return (<div>
<div>
<button onClick={() => {
navigate("/");
}}>Landing Page</button>
<button onClick={() => {
navigate("/Dashboard");
}}>Dashboard Page</button>
</div>
</div>)
}
export default App
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment