我希望仅在“/checkout”和“/”期间可见,而不是在整个路径中可见。在 react reuter dom v6 中很难做到。
import React from "react";
import "./App.css";
import Header from "./Header";
import Home from "./Home";
import Checkout from "./Checkout";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Login from "./Login";
function App() {
return (
// BEM
<BrowserRouter>
<div className="app">
<Header />
<Routes>
<Route path="/" element={<Home />}></Route>
<Route path="/checkout" element={<Checkout />}></Route>
<Route path="/login" element={<Login />}></Route>
</Routes>
</div>
</BrowserRouter>
);
}
export default App;