概述:通过 useNavigate() hook 实现
import {
BrowserRouter,
Routes,
Route,
useNavigate,
} from "react-router-dom";
export default function App(){
return(
<BrowserRouter>
<Routes>
<Route path="/" element={<Index />}></Route>
<Route path="/home" element={<Home />}></Route>
</Routes>
</BrowserRouter>
)
}
function Index(){
let navigate = useNavigate()
return(
<button onClick={() => navigate("/home")}>to: home</button>
)
}
function Home(){
let navigate = useNavigate()
return(
<button onClick={() => navigate("/")}>to: index</button>
)
}
Comments | NOTHING