Created
May 26, 2017 10:22
-
-
Save wzup/2a94e415551f82ce416b7952f9af070f 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
'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