react 學習筆記

1.Routerhtml

1.1 Historiesreact

 React Router 是創建在 history 之上的。一個 history 知道如何去監聽瀏覽器地址欄的變化, 並解析這個 URL 轉化爲 location 對象, 而後 router 使用它匹配到路由,最後正確地渲染對應的組件。webpack

 

經常使用的 history 有三種形式, 可是你也能夠使用 React Router 實現自定義的 history。git

1.2 IndexRoute
github

  IndexRoute 表明Route 級別的默認路徑,同時,須要包在Route內,目錄結構以下:web

<Router history={browserHistory}>
    <Route path="/" component={App}>
      {/*IndexRoute 表明默認路由,如 url 爲:  localhost:8080/   ,默認讀取Respos;若是 url爲: localhost:8080/about 讀取About component ;
    若是不指定 IndexRoute ,默認爲undefined, 訪問localhost:8080/ 將不顯然任何component
*/} <IndexRoute component={Repos} /> <Route path="/about" component={About}/> </Route> </Router>

 1.3 Paramsapi

相關文章
相關標籤/搜索