首页 > 代码库 > react-router4 嵌套路由
react-router4 嵌套路由
先直接贴代码
import React from ‘react‘; import ReactDOM from ‘react-dom‘; import { HashRouter as Router, Route, Switch} from ‘react-router-dom‘; import createBrowserHistory from ‘history/createBrowserHistory‘; import UserAddPage from ‘./pages/UserAdd/index‘; import HomePage from ‘./pages/Home/index‘; import HomeLayout from ‘./components/HomeLayout/index‘; const hashHistory = createBrowserHistory(); const NoMatch = ({ location }) => ( <div> <h3>无法匹配 <code>{location.pathname}</code></h3> </div> ) ReactDOM.render(( <Router history={hashHistory}> <div> <HomeLayout>//总会加载这个组件,并且下面 swicth 里面的组件会在它里面 render <Switch> <Route path="/" exact component={HomePage}/> <Route path="/user/add" component={UserAddPage}/> <Route component={NoMatch}/> </Switch> </HomeLayout> </div> </Router> ), document.getElementById(‘root‘));
https://stackoverflow.com/questions/42095600/nested-routes-in-v4
react-router4 嵌套路由
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。