Use react route react-router-dom
vue react and are using the same encapsulation history to jump page, here is what react commonly used routing plug-react-router-dom this thing on GitHub is now the most popular
Prime Minister or to download
npm i react-router-dom
Introduction:
It is recommended to create a new file separate router.js agree to manage your route
router.js:
import React from 'react'; import {HashRouter, Route, Switch} from 'react-router-dom'; import {Home} from "./page/home/home"; //引入的组件 import {Mine} from "./page/mine/mine";//引入的组件 const BasicRoute = () => ( <HashRouter> <Switch> {/*//定义路由地址*/} <Route exact path="/home" component={Home}/> <Route exact path="/" component={Mine}/> </Switch> </HashRouter> ); export default BasicRoute;
Then this is the entrance page I app.js introduced router.js files on it
import React from 'react'; import Router from "./router"//引入router.js import './App.css'; import './style/public.less'; function App() { return ( <div className="App"> <Router/> </div> ); } export default App;
vue react and are using the same encapsulation history to jump page, here is what react commonly used routing plug-react-router-dom this thing on GitHub is now the most popular
Prime Minister or to download
npm i react-router-dom
Introduction:
It is recommended to create a new file separate router.js agree to manage your route
router.js:
import React from 'react'; import {HashRouter, Route, Switch} from 'react-router-dom'; import {Home} from "./page/home/home"; //引入的组件 import {Mine} from "./page/mine/mine";//引入的组件 const BasicRoute = () => ( <HashRouter> <Switch> {/*//定义路由地址*/} <Route exact path="/home" component={Home}/> <Route exact path="/" component={Mine}/> </Switch> </HashRouter> ); export default BasicRoute;
Then this is the entrance page I app.js introduced router.js files on it
import React from 'react'; import Router from "./router"//引入router.js import './App.css'; import './style/public.less'; function App() { return ( <div className="App"> <Router/> </div> ); } export default App;