Answers for "how to redirect to a route in react router 6"

8

redirect react router

<Route exact path="/">
  {loggedIn ? <Redirect to="/profile" /> : <HomePage />}
</Route>
Posted by: Guest on March-07-2020
0

redirect with react router v6

import { BrowserRouter, Navigate, Route, Routes } from 'react-router-dom';

<BrowserRouter>
  <Routes>
    <Route path="/" element={<Home />} />
    <Route path="/lab" element={<Lab />} />
    <Route
        path="*"
        element={<Navigate to="/" replace />}
    />
  </Routes>
</BrowserRouter>
Posted by: Guest on April-27-2022

Code answers related to "how to redirect to a route in react router 6"

Code answers related to "Javascript"

Browse Popular Code Answers by Language