Skip to content

Instantly share code, notes, and snippets.

@codepunkt
Last active October 18, 2022 16:04
Show Gist options
  • Save codepunkt/ae82a0f3b9deb93908dc1f3d5bbc8da2 to your computer and use it in GitHub Desktop.
Save codepunkt/ae82a0f3b9deb93908dc1f3d5bbc8da2 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,
},
},
}
@gurukatre
Copy link

Thank you Christoph

The information is very use full.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment