Last active
July 26, 2017 03:03
-
-
Save Houserqu/ec014b3fd18ed872ebfc85ebd277527d to your computer and use it in GitHub Desktop.
react-router常用代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //获取当前路由 | |
| let path = hashHistory.getCurrentLocation().pathname; | |
| //路由跳转 | |
| hashHistory.push('/'); | |
| //路由示例 | |
| <Router history={hashHistory}> | |
| <Route path='/' component={Tabbar}> //每次都会加载 Tabbar | |
| <IndexRoute component={Index} /> // '/'加载的路由 | |
| <Route path='sort' component={Sort}/> | |
| <Route path='me' component={Me} /> | |
| </Route> | |
| <Route onEnter={checkLogin}> //访问路径前执行的方法 | |
| <Route path='publish' component={Publish}/> | |
| <Route path='registervip' component={RegisterVip} /> | |
| </Route> | |
| </Router> | |
| //获取路由参数 | |
| this.props.params.XXX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment