Skip to content

Instantly share code, notes, and snippets.

@Houserqu
Last active July 26, 2017 03:03
Show Gist options
  • Save Houserqu/ec014b3fd18ed872ebfc85ebd277527d to your computer and use it in GitHub Desktop.
Save Houserqu/ec014b3fd18ed872ebfc85ebd277527d to your computer and use it in GitHub Desktop.
react-router常用代码
//获取当前路由
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