1.安装插件
npm install react-router-dom --save-dev
2.新建路由
//routes.js
import React from 'react'
import {
BrowserRouter as Router,
Route,
} from 'react-router-dom'
import App from './App'
import App2 from './App2'
import App3 from './App3'
const Routers = () => (
<Router>
<div>
<Route exact path="/" component={App}/>
<Route path="/app" component={App}/>
<Route path="/app2" component={App2}/>
<Route path="/app3" component={App3}/>
</div>
</Router>
)
export default Routers
3.路由跳转
//顶部添加
import {Link} from 'react-router-dom'
//跳转实现
<Link to="/app2">app2</Link>
<Link to="/app2">app3</Link>