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

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM