react-router4 嵌套路由的使用方法
更新時間:2017年07月24日 15:03:45 作者:isykw
本篇文章主要介紹了react-router4 嵌套路由的使用方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
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'));
參考文章:https://stackoverflow.com/questions/42095600/nested-routes-in-v4
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。
相關文章
react native基于FlatList下拉刷新上拉加載實現(xiàn)代碼示例
這篇文章主要介紹了react native基于FlatList下拉刷新上拉加載實現(xiàn)代碼示例2018-09-09React使用fullpage.js實現(xiàn)整屏翻頁功能
最近筆者在完成一個移動端小項目的過程中需要實現(xiàn)整屏翻頁的效果;調研完畢之后,最終決定使用pullPage.js實現(xiàn)此功能,fullPage.js使用起來比較方便,并且官網上也給了在react項目中使用的demo,本文記錄了這個第三方庫的使用過程,感興趣的朋友可以參考下2023-11-11React中的useState和setState的執(zhí)行機制詳解
這篇文章主要介紹了React中的useState和setState的執(zhí)行機制,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03React?SSR架構Streaming?Render與Selective?Hydration解析
這篇文章主要為大家介紹了React?SSR架構Streaming?Render與Selective?Hydration解析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-03-03