<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12

      React-router的基本使用

      1、安裝使用

      $ npm install -S react-router
      import { Router, Route, hashHistory } from 'react-router';
      
      render((
        <Router history={hashHistory}>
          <Route path="/" component={App}/>
        </Router>
      ), document.getElementById('app'));

      1.1、版本問題

      react-router 有多個版本,2.x/3.x  - 4.x版本有比較大的改動,并且互相不兼容,2.x/3.x 和 4.x 版本的語法有非常大的不同。并且 react-router 和 react 的某些版本也會有沖突

      目前使用 react-router 的 3.x 版本下面的版本可以運行成功。

      "dependencies": {
          "react": "^16.2.0",
          "react-dom": "^16.2.0",
          "react-router": "^3.0.2",
          "react-scripts": "3.1.1"
      }

      2、Router 組件

      2.1、JSX 的 Route 組件實現路由

      路由器Router就是React的一個組件。Router組件本身只是一個容器,真正的路由要通過Route組件定義。

      //入口文件 index.js
      import React from 'react';
      import ReactDOM from 'react-dom';
      import { Router, Route, hashHistory } from 'react-router';
      
      ReactDOM.render((
        <Router history={hashHistory}>
         <Route path="/" component={App}>
           <Route path="/repos" component={Repos}/>
         </Route>
      </Router>
      ), document.getElementById('app'));

       

      2.1、route 數組對象實現路由

      子路由也可以不寫在Router組件里面,單獨傳入Router組件的routes屬性。

      let routes = <Route path="/" component={App}>
        <Route path="/repos" component={Repos}/>
      </Route>;
      
      <Router routes={routes} history={browserHistory}/>

      或者是更方便的寫法(推薦寫法):

      const routes = [{
        path: '/',
        component: App,
        indexRoute: { component: DefaultComponent },
        childRoutes: [
          { path: 'about', component: About },
          { path: 'inbox', component: Inbox },
        ]
      }]
      
      React.render(<Router routes={routes} />, document.body)

       

      3、路徑匹配的組件

      react-router 是按 URL 來匹配組件的。

      React.render((
        <Router>
          <Route path="/" component={App}>
            <Route path="about" component={About} />
            <Route path="inbox" component={Inbox}>
              <Route path="messages/:id" component={Message} />
            </Route>
          </Route>
        </Router>
      ), document.body)

      如果 URL 匹配到某個組件,并且 URL 上并沒有該組件的上層組件(即包含著它的上層 Route),此時仍然會匹配到該組件的上層 Route。

      比如下面:用絕對路徑表示 Message 組件,當 URL 是 /message/aaa 時,仍會匹配到 APP 和 Inbox 組件,然后再是 Message 組件。

      React.render((
        <Router>
          <Route path="/" component={App}>
            <IndexRoute component={Dashboard} />
            <Route path="about" component={About} />
            <Route path="inbox" component={Inbox}>
              {/* 使用 /messages/:id 替換 messages/:id */}
              <Route path="/messages/:id" component={Message} />
            </Route>
          </Route>
        </Router>
      ), document.body)

       想要在某組件內渲染它的下層即子路由,在組件內使用 {this.props.children} 語法。

      posted @ 2019-08-21 10:29  wenxuehai  閱讀(2657)  評論(0)    收藏  舉報
      //右下角添加目錄
      主站蜘蛛池模板: 福利一区二区在线观看| 亚洲精品毛片一区二区| 亚洲中文字幕伊人久久无码 | 日本中文字幕有码在线视频| 最近中文字幕免费手机版| 国产精品成人午夜福利| 国产精品人成视频免| 蜜桃av亚洲精品一区二区| 亚洲日本欧美日韩中文字幕| 久久天堂无码av网站| 无码人妻一区二区三区线| 亚洲精品中文字幕在线观| 成人国产乱对白在线观看| 久久综合色一综合色88欧美| 国产中文字幕一区二区| 国产一二三五区不在卡| 亚洲av无码成人精品区一区| 精品一区二区免费不卡| 国产精品一区二区日韩精品| 午夜一区二区三区视频| 妺妺窝人体色www看美女| 中文文字幕文字幕亚洲色| 国产av熟女一区二区三区| 欧美黑人又粗又大久久久| 国产午夜91福利一区二区| 国产精品福利自产拍久久| 成人亚洲欧美一区二区三区| 亚洲精品日韩中文字幕| 霍州市| 午夜免费视频国产在线| 免费无码成人AV片在线| 日韩无专区精品中文字幕| 亚洲AV无码午夜嘿嘿嘿| 亚洲综合色区另类av| 国产国语一级毛片| 国产精品三级一区二区三区| 国产午夜亚洲精品国产成人| 卡一卡2卡3卡精品网站| 亚洲中文一区二区av| 国产精品一区二区三区自拍| 亚洲成人av在线系列|