Skip to content

Instantly share code, notes, and snippets.

@webkreation
Forked from codepunkt/config.json
Created December 2, 2018 10:16
Show Gist options
  • Select an option

  • Save webkreation/78591c0607785a6b38b4c44963f95a5d to your computer and use it in GitHub Desktop.

Select an option

Save webkreation/78591c0607785a6b38b4c44963f95a5d to your computer and use it in GitHub Desktop.
Host react app built with webpack in non-root directory
{
"basePath": "/"
}
// usage with react-router-redux
import { ConnectedRouter } from 'react-router-redux'
import { basePath as basename } from './config.json'
const history = createHistory({ basename })
ReactDOM.render(
<ConnectedRouter history={history}>
<App />
</ConnectedRouter>,
document.querySelector('#app')
)
// usage with react-router
import { BrowserRouter } from 'react-router-dom'
import { basePath as basename } from './config.json'
ReactDOM.render(
<BrowserRouter basename={basename}>
<App />
</BrowserRouter>,
document.querySelector('#app')
)
var publicPath = require('./config.json').basePath
module.exports = {
output: {
publicPath,
},
devServer: {
publicPath,
historyApiFallback: {
index: publicPath,
},
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment