react-router4 嵌套路由的使用方法
react我自己還在摸索學(xué)習(xí)中,今天正好學(xué)習(xí)一下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>無(wú)法匹配 <code>{location.pathname}</code></h3>
</div>
)
ReactDOM.render((
<Router history={hashHistory}>
<div>
<HomeLayout>//總會(huì)加載這個(gè)組件,并且下面 swicth 里面的組件會(huì)在它里面 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
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
相關(guān)文章
React Native實(shí)現(xiàn)地址挑選器功能
這篇文章主要為大家詳細(xì)介紹了React Native仿地址挑選器功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-10-10
詳解React開(kāi)發(fā)中使用require.ensure()按需加載ES6組件
本篇文章主要介紹了詳解React開(kāi)發(fā)中使用require.ensure()按需加載ES6組件,非常具有實(shí)用價(jià)值,需要的朋友可以參考下2017-05-05
react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼
本文主要介紹了react實(shí)現(xiàn)組件狀態(tài)緩存的示例代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2023-02-02
React實(shí)現(xiàn)簡(jiǎn)單登錄的項(xiàng)目實(shí)踐
登錄、注冊(cè)、找回密碼是前端項(xiàng)目經(jīng)常遇到的需求,本文主要介紹了React實(shí)現(xiàn)簡(jiǎn)單登錄的項(xiàng)目實(shí)踐,具有一定的參考價(jià)值,感興趣的可以了解一下2024-01-01
react項(xiàng)目中@路徑簡(jiǎn)單配置指南
這篇文章主要給大家介紹了關(guān)于react項(xiàng)目中@路徑簡(jiǎn)單配置的相關(guān)資料,文中還介紹了React配置@路徑別名的方法,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-09-09
React Native之ListView實(shí)現(xiàn)九宮格效果的示例
本篇文章主要介紹了React Native之ListView實(shí)現(xiàn)九宮格效果的示例,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-08-08

