码迷,mamicode.com
首页 > 其他好文 > 详细

react-router4 嵌套路由

时间:2017-06-04 18:37:32      阅读:327      评论:0      收藏:0      [点我收藏+]

标签:home   tps   his   render   add   ges   .com   代码   nested   

先直接贴代码

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 嵌套路由

标签:home   tps   his   render   add   ges   .com   代码   nested   

原文地址:http://www.cnblogs.com/isykw/p/6941106.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!