步骤:安装路由
1yarn add react-router-dom
2导入路由文件Router/router/link
3在pages文件中创建Home/index。js和cotyList/index。两个页面
4使用Router配置首页和城市选择页面
import React from "react"; import {Button} from "antd-mobile" import {BrowserRouter as Router,Route,link, Link} from "react-router-dom" //导入要使用的组件 import Home from "./pages/Home" import CityList from "./pages/CityList" function App() { return ( <Router> <div className="App"> {/* 配置路由入口 */} <Link to="/home">首页</Link> <Link to="/citylist">城市数据</Link> {/* 配置路由 */} <Route path="/home" component={Home}></Route> <Route path="/citylist" component={CityList}></Route> </div> </Router> ); } export default App;