Skip to content

Instantly share code, notes, and snippets.

@andreypopp andreypopp/plugins.js
Last active Aug 29, 2015

Embed
What would you like to do?
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
You can’t perform that action at this time.