美文网首页
React-Route相关

React-Route相关

作者: LElysion | 来源:发表于2017-03-07 15:32 被阅读0次

官方教程

react-route官方教程非常完善,而且一步一步,通俗易懂,入门可以参看官方教程
https://github.com/reactjs/react-router-tutorial
进阶示例
https://github.com/ReactTraining/react-router

最简单的示例

render((
  <Router history={browserHistory}> /*浏览器历史*/
    <Route path="/" component={App}> /*渲染'/'下的组件为App*/
      <Route path="about" component={About}/>
      <Route path="users" component={Users}>
        <Route path="/user/:userId" component={User}/>/*获取:userId作为地址*/
      </Route>
      <Route path="*" component={NoMatch}/>
    </Route>
  </Router>
), document.getElementById('root'))

可以用于跳转的a标签

/*跳转方法*/
goHome() {
  this.context.router.push('/');//可以是任何路由
}
/*组件*/
render(
  ...
<a href="javascript:void(0)"
onClick={()=>this.goHome()} >gohome</a>
  ...
)
/*为组件添加propTypes属性以使用上述方法*/
TheComp.contextTypes = {
    router: React.PropTypes.object.isRequired
}

路由容器

未完待续

相关文章

  • React-Route相关

    官方教程 react-route官方教程非常完善,而且一步一步,通俗易懂,入门可以参看官方教程https://gi...

  • react-route 4

    官网: https://reacttraining.com/react-router/web/guides/phi...

  • React-Router (1)

    首先对于 react 来说,即便是没有使用 react-route 也是可以完成需求的,使用 react 提供的 ...

  • react route使用HashRouter和BrowserR

    踩坑经历 昨天看了篇关于react-route的文章,说BrowserRouter比HashRouter好一些,r...

  • Reactjs路由组件x-react-router

    原本想用react-route、react-routing命名,但是,npm中都已经有了。x表示extend先附上...

  • react-route详细文档

    使用 HTML5 提供的 history API (pushState, repl...

  • react-route路由监听

    react-route v3项目中写了一个自动生产文档的系统, 其中有一个比较烦人的需求,就是项目中的面包屑是根据...

  • react-route browserHistory apach

    添加apache的.htaccess文件,文件内容为: RewriteEngine OnRewriteBase ...

  • React-Route学习总结

    React-Router是React的一个路由库,主要是管理URL,实现组件间的切换、state的变化。 Reac...

  • React Router源码分析

    前言 发现react-route用Link或Push跳转时,没有刷新页面,但是Url变了,而且点击浏览器自动的返回...

网友评论

      本文标题:React-Route相关

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