Skip to content

Instantly share code, notes, and snippets.

@wzup
Created May 26, 2017 10:22
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 wzup/2a94e415551f82ce416b7952f9af070f to your computer and use it in GitHub Desktop.
Save wzup/2a94e415551f82ce416b7952f9af070f to your computer and use it in GitHub Desktop.
'use strict';
const NODE_ENV = process.env.NODE_ENV || 'development';
const React = require('react');
import { StaticRouter, BrowserRouter, Route, Link } from 'react-router-dom';
import { ConnectedRouter } from 'react-router-redux';
/**
* This is only Router. Without routes. I pass keep routes in a separate module and pass them in here, params.routes
* This is how I separate it for browser and server environment
* Look at browser.js and server.js and you will see how env prop is passed here
*/
function getRouter(params) {
if(params.env == 'browser') {
return (
<BrowserRouter router={params.routerConf}>
{params.routes}
</BrowserRouter>
);
}
if(params.env == 'server') {
return (
<StaticRouter
basename='/'
location={params.url}
context={params.context}>
{params.routes}
</StaticRouter>
)
}
}
module.exports = getRouter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment