Skip to content

Instantly share code, notes, and snippets.

@ericmuyser ericmuyser/react.js
Created Oct 29, 2015

Embed
What would you like to do?
// client/app/router.jsx
// Setup routes
// For different templates based on domain
var SiteRoutes = {
'test1.com': (
<Route handler={ReactRouter.RouteHandler}>
<Route path='/' handler={require('./routes/test1.com/home.jsx')} />
<Route path='/sets' handler={require('./routes/test1.com/sets.jsx')} />
<Route path='/sets/:action' handler={require('./routes/test1.com/sets.jsx')} />
<Route path='/sets/:setId/:action' handler={require('./routes/test1.com/sets.jsx')} />
</Route>
),
'test2.com': (
<Route handler={ReactRouter.RouteHandler}>
<Route path='/' handler={require('./routes/test2.com/home.jsx')} />
</Route>
)
};
// Base templates
var RouteHandlers = (
<Route handler={ReactRouter.RouteHandler}>
<DefaultRoute handler={require('./routes/default/home.jsx')} />
<NotFoundRoute name='not-found' handler={require('./routes/default/notfound.jsx')} />
{Ace.site.host in SiteRoutes ? SiteRoutes[Ace.site.host] : DummyRoute}
<Route path='/' handler={require('./routes/default/home.jsx')} />
<Route path='/login' handler={require('./routes/default/login.jsx')} />
<Route path='/register' handler={require('./routes/default/register.jsx')} />
<Route path='/account/dashboard' handler={require('./routes/default/account/dashboard.jsx')} />
<Route path='/sets' handler={require('./routes/default/sets.jsx')} />
<Route path='/sets/create' handler={require('./routes/default/sets/create.jsx')} />
<Route path='/sets/:setId' handler={require('./routes/default/sets/view.jsx')} />
<Route path='/sets/:setId/edit' handler={require('./routes/default/sets/edit.jsx')} />
<Route path='/admin' handler={require('./routes/default/admin.jsx')} />
<Route path='/admin/dashboard' handler={require('./routes/default/admin/dashboard.jsx')} />
<Route path='/admin/sets' handler={require('./routes/default/admin/sets.jsx')} />
<Route path='/admin/sets/create' handler={require('./routes/default/admin/sets/create.jsx')} />
<Route path='/admin/sets/:page' handler={require('./routes/default/admin/sets.jsx')} />
<Route path='/admin/sets/:setId/edit' handler={require('./routes/default/admin/sets/edit.jsx')} />
</Route>
);
// Server.js
var routes = require('../client/app/router.jsx').routes;
var renderApp = function(req, res, cb) {
var router = ReactRouter.create({
routes: routes,
location: req.url,
onAbort: function(redirect) {
cb({redirect: redirect});
},
onError: function(err) {
console.log(err);
}
});
router.run(function(Handler, state) {
if (!state.routes.length) {
cb('[Ace] No routes found!');
return;
}
if(state.routes[1].name === 'not-found') {
cb('[Ace] No routes found!');
//cb({notFound: true}, React.renderToStaticMarkup(<Handler />));
return;
}
cb(null, React.renderToStaticMarkup(<Handler />));
});
};
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.