react-router4 嵌套路由的使用方法
react我自己还在摸索学习中,今天正好学习一下react-router4嵌套路由的使用方法,顺便留着笔记
先直接贴代码
importReactfrom'react'; importReactDOMfrom'react-dom'; import{HashRouterasRouter,Route,Switch}from'react-router-dom'; importcreateBrowserHistoryfrom'history/createBrowserHistory'; importUserAddPagefrom'./pages/UserAdd/index'; importHomePagefrom'./pages/Home/index'; importHomeLayoutfrom'./components/HomeLayout/index'; consthashHistory=createBrowserHistory(); constNoMatch=({location})=>() ReactDOM.render((无法匹配
{location.pathname}
),document.getElementById('root'));//总会加载这个组件,并且下面swicth里面的组件会在它里面render
参考文章:https://stackoverflow.com/questions/42095600/nested-routes-in-v4
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。