3-1 安装依赖
yarn add react-router-dom
3-1 配置路由
App.js
import React, { Component } from 'react';
import {
BrowserRouter as Router,
Switch,
Route,
Link
} from "react-router-dom";
import Home from './views/Home'
import About from './views/About'
class App extends Component {
render() {
return (
<div>
<Router>
<ul>
<li><Link to="/">首页</Link></li>
<li><Link to="/about">About</Link></li>
</ul>
{/* exact路由的严格匹配,只有路径为/才会加载对应的路由 */}
<Switch>
<Route exact path="/" component={Home}></Route>
<Route path="/about" component={About}></Route>
<Route path="/about/fs" component={About}></Route>
</Switch>
</Router>
</div>
);
}
}
export default App;