代码展示 import React, { Component } from "react"; import Div1 from "./components/div1"; import Div2 from "./components/div2"; import Page1 from "./pages/page1"; import Page2 from "./pages/page2"; import { Link, BrowserRouter, Route, NavLink, Switch, HashRouter, Redirect, } from "react-router-dom"; export default class App extends Component { render() { return ( <div> <HashRouter> <NavLink activeClassName="acc" to="/a"> a </NavLink> <NavLink activeClassName="acc" to="/b/c/d"> b </NavLink> <Switch> <Route path="/a" component={Page1} /> <Route path="/b" component={Page2} /> <Redirect to="/a" /> </Switch> </HashRouter> <Div1>123456789/Div1</Div1> </div> ); } } 运行效果