“react-router-dom v6 redirect” Kode Jawaban

react-router-dom v6 redirect

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

function App() {
  return (
    <Routes>
      <Route path="/home" element={<Home />} />
      <Route path="/" element={<Navigate replace to="/home" />} />
    </Routes>
  );
}
Unsightly Unicorn

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

Jawaban yang mirip dengan “react-router-dom v6 redirect”

Pertanyaan yang mirip dengan “react-router-dom v6 redirect”

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya