Last active
August 29, 2015 13:57
-
-
Save andreypopp/9571774 to your computer and use it in GitHub Desktop.
This file contains 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
var React = require('react'); | |
var Router = require('react-router-component'); | |
var Link = Router.Link; | |
var Locations = Router.Locations; | |
var Location = Router.Location; | |
var plugins = [ | |
{title: 'Reports', path: '/reports', handler: ReportHandler}, | |
... | |
]; | |
/** | |
* Main application component, | |
* generates top-level menu and a top level router from plugins. | |
*/ | |
var App = React.createClass({ | |
render: function() { | |
var locations = ( | |
<Locations> | |
{this.props.plugins.map(function(p) { | |
return <Location path={p.path + '/*'} handler={p.handler} /> | |
})) | |
</Locations> | |
); | |
var menuItems = this.props.plugins.map(function(p) { | |
return <Link href={p.path}>{p.title}</Link> | |
}); | |
return ( | |
<div> | |
<div className="menu"> | |
{menuItems} | |
</div> | |
<div className="content"> | |
<Locations> | |
{locations} | |
</Locations> | |
</div> | |
</div> | |
); | |
} | |
}); | |
/** | |
* Reports plugin component | |
* It is router which can be mounted under another router. | |
* It also can generate submenu for its own routes. | |
*/ | |
var ReportHandler = React.createClass({ | |
render: function() { | |
<Locations contextual> | |
<Location path="/" handler={ReportsMain} /> | |
<Location path="/visits" handler={VisitsReport} /> | |
</Locations> | |
} | |
}); | |
React.renderComponent(App({plugins: plugins}), document.body); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment