Skip to content

Instantly share code, notes, and snippets.

@insin
Last active August 29, 2015 14:10
Show Gist options
  • Save insin/f8f04d46a82c2832a3e0 to your computer and use it in GitHub Desktop.
Save insin/f8f04d46a82c2832a3e0 to your computer and use it in GitHub Desktop.
Getting the route <RouteHandler/> will render - API for this?
var {Route, RouteHandler} = ReactRouter
var App = React.createClass({
contextTypes: {
getRouteAtDepth: React.PropTypes.func.isRequired,
routeHandlers: React.PropTypes.array.isRequired
},
render() {
var route = this.context.getRouteAtDepth(this.context.routeHandlers.length - 1)
return <div className={route.handler.fluid ? 'container-fluid' : 'container'}>
<RouteHandler/>
</div>
}
})
var RegularThing = React.createClass({
render() {
// ...
}
})
var HugeThing = React.createClass({
statics: {
fluid: true
},
render() {
// ...
}
})
var routes = <Route handler={App} path="/">
<Route name="regular" path="/regular" handler={RegularThing}/>
<Route name="huge" path="/huge" handler={HugeThing}/>
</Route>
ReactRouter.run(routes, function(Handler) {
React.render(<Handler/>, document.body)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment