“React Router 6 Redirect” Kode Jawaban

Redirect React Router

<Route exact path="/">
  {loggedIn ? <Redirect to="/profile" /> : <HomePage />}
</Route>
Kaotik

Redirect dengan 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 />} //this is a way to redirect
    />
  </Routes>
</BrowserRouter>
Adnane Afifi

Redirect dengan 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>
Adnane Afifi

React Router 6 Redirect

<Route
            path="/signin"
            element={
              this.props.currentUser ? (
                <Navigate to="/" replace />
              ) : (
                <SignInAndSignUpPage />
              )
            }
          />
Freexe

Jawaban yang mirip dengan “React Router 6 Redirect”

Pertanyaan yang mirip dengan “React Router 6 Redirect”

Lebih banyak jawaban terkait untuk “React Router 6 Redirect” di JavaScript

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya