当前位置: 移动技术网 > IT编程>开发语言>JavaScript > react-router4 嵌套路由的使用方法

react-router4 嵌套路由的使用方法

2017年12月12日  | 移动技术网IT编程  | 我要评论

react我自己还在摸索学习中,今天正好学习一下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'));

参考文章:

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持移动技术网。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网