1. 安装 npm install --save react-router-dom 2. 引入 import { BrowserRouter as Router, Route, Link } from "react-router-dom"; 3. 引入模块 import Home from ‘./page/Home.js‘; 4. 实现代码 Router div ul li Link to="/"Home/Link /l
1. 安装
npm install --save react-router-dom
2. 引入
import { BrowserRouter as Router, Route, Link } from "react-router-dom";
3. 引入模块
import Home from ‘./page/Home.js‘;
4. 实现代码
<Router> <div> <ul> <li> <Link to="/">Home</Link> </li> <li> <Link to="/about">About</Link> </li> <li> <Link to="/topics">Topics</Link> </li> </ul> <hr /> <Route exact path="/" component={Home} /> <Route path="/about" component={About} /> <Route path="/topics" component={Topics} /> </div> </Router>