源码网商城,靠谱的源码在线交易网站 我的订单 购物车 帮助

源码网商城

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

  • 时间:2021-02-03 14:04 编辑: 来源: 阅读:
  • 扫一扫,手机访问
摘要:react-router4 嵌套路由的使用方法
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'));
参考文章:[url=https://stackoverflow.com/questions/42095600/nested-routes-in-v4]https://stackoverflow.com/questions/42095600/nested-routes-in-v4[/url] 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持编程素材网。
  • 全部评论(0)
联系客服
客服电话:
400-000-3129
微信版

扫一扫进微信版
返回顶部