“REACT-ROUTER-DOM V6 redirecionamento” Respostas de código

REACT-ROUTER-DOM V6 redirecionamento

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

Redirecionar com o 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

Redirecionar com o 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

Respostas semelhantes a “REACT-ROUTER-DOM V6 redirecionamento”

Perguntas semelhantes a “REACT-ROUTER-DOM V6 redirecionamento”

Procure respostas de código populares por idioma

Procurar outros idiomas de código