Support webpack-dev-server historyApiFallback: true
See original GitHub issueHi I don’t know exactly is this issue with webpack but i think so I have simple config for router
var ReactappApp = require('./ReactappApp');
var HelloWorld = require('./HelloWorld');
var React = require('react');
var Router = require('react-router');
var Route = Router.Route;
var content = document.getElementById('content');
var Routes = (
<Route path="/" handler={ReactappApp}>
<Route name="hello" path="hello" handler={HelloWorld}/>
</Route>
);
console.log(Routes);
Router.run(Routes,Router.HistoryLocation, function (Handler) {
React.render(<Handler/>, content);
});
So i try to load HelloWorld component at /hello and get Cannot GET /hello So server doesn’t see this route
I use grunt and connect also. Here is grunt task for webpack:
'webpack-dev-server': {
options: {
hot: true,
port: 8000,
webpack: webpackDevConfig,
publicPath: '/assets/',
contentBase: './<%= pkg.src %>/'
}
and here is webpack config https://gist.github.com/fellz/b2cc0de81c7b1f5bf442#file-webpack-config
with historyApiFallback: true
'webpack-dev-server': {
options: {
hot: true,
port: 8000,
webpack: webpackDevConfig,
publicPath: '/assets/',
contentBase: './<%= pkg.src %>/',
historyApiFallback: true
}
it’s loading ReactappApp instead of HelloWorld
p.s. react-router-component works as expected and perfectly well
Issue Analytics
- State:
- Created 9 years ago
- Reactions:7
- Comments:42 (9 by maintainers)
Top Results From Across the Web
DevServer - webpack
webpack -dev-server can be used to quickly develop an application. See the development guide ... Enable devServer.historyApiFallback by setting it to true :....
Read more >historyApiFallback doesn't work in Webpack dev server
historyApiFallback.index indicate that when url path not match a true file,webpack-dev-server use the file config in ...
Read more >Support webpack-dev-server historyApiFallback: true #676
A hackish but simpler way to do that is to inject a middleware (note this relies on undocumented property and may stop working...
Read more >historyApiFallback troubles with webpack-dev-server and ...
In your webpack config file, add the devServer root level property, set to an object with historyApiFallback: true like so:.
Read more >History API Routing for SPAs using webpack-dev-server
We need to enable the so-called History API Fallback which basically means the server should fallback to serve index.html in case the requested ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’ve been struggling with this for longer than I’d like to admit, but I’ve just figured it out.
Besides enabling
historyApiFallback
, if you’re having trouble only with nested routes, check your html file’s reference to your script.In my case, it was the difference between
<script src="/bundle.js"></script>
and<script src="bundle.js"></script>
causing problems on nested routes. Basic stuff, and super obvious now that I’ve found it, but it was easy to miss.Thanks to @adrianmacneil for the sample app, it was a big help.
edit - “/bundle.js” being the correct src, so the reference isn’t taken as relative to the current path.
Some of the examples above are very complicated. In most cases you can get this working simply by adding the following lines to your
webpack.config.js
file:I made an example app to help anyone else looking for a solution to this (like I was).