Skip to content

Instantly share code, notes, and snippets.

@cellog
Created January 14, 2017 08:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cellog/df4422c48fd065afcc24f8dc3af336ce to your computer and use it in GitHub Desktop.
Save cellog/df4422c48fd065afcc24f8dc3af336ce to your computer and use it in GitHub Desktop.
react-router with nested routes
import React, { Component } from 'react'
export default class Inbox extends Component {
render() {
return (
<div>
<h2>Inbox</h2>
{this.props.children || "Welcome to your Inbox"}
</div>
)
}
}
export default () => <Router>
<Route path="/" component={App}>
<IndexRoute component={Dashboard} />
<Route path="about" component={About} />
<Route path="inbox" component={Inbox} />
{/* Use /messages/:id instead of /inbox/messages/:id */}
<Route component={Inbox}>
<Route path="messages/:id" component={Message} />
</Route>
</Route>
</Router>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment