美文网首页
react-router

react-router

作者: 游荡的猫咪 | 来源:发表于2017-05-24 16:41 被阅读0次
react-router安装命令
npm install -S react-router
react-router的使用
import { Router, Route, hashHistory } from 'react-router';
render((
  <Router history={hashHistory}>
    <Route path="/" component={App}/>
  </Router>
), document.getElementById('app'));

Router组件有一个参数history,它的值hashHistory表示,路由的切换由URL的hash变化决定

嵌套路由
<Router history={hashHistory}>
  <Route path="/" component={App}>
    <Route path="/repos" component={Repos}/>
    <Route path="/about" component={About}/>
  </Route>
</Router>

用户访问repos组件的时候会先加载app再加载repos

IndexRoute

默认情况下加载的组件

<Router>
  <Route path="/" component={App}>
    <IndexRoute component={Home}/>
    <Route path="accounts" component={Accounts}/>
    <Route path="statements" component={Statements}/>
  </Route>
</Router>

相关文章

网友评论

      本文标题:react-router

      本文链接:https://www.haomeiwen.com/subject/okroxxtx.html