npm install react-router-dom
// 目前版本: v6.3
官方案例:
- import { render } from "react-dom";
- import {
- BrowserRouter,
- Routes,
- Route
- } from "react-router-dom";
-
- import App from "./App";
- import Expenses from "./routes/expenses";
- import Invoices from "./routes/invoices";
-
- const rootElement = document.getElementById("root");
- render(
- <BrowserRouter>
- <Routes>
- <Route path="/" element={<App />} />
- <Route path="/expenses" element={<Expenses />} />
- <Route path="/invoices" element={<Invoices />} />
- Routes>
- BrowserRouter>,
- rootElement
- );
BrowserRouter为history模式
HashRo