This option enables History API Fallback
support in webpack-dev-server
, effectively asking the server to fallback to
index.html
in the event that a requested resource cannot be found.
webpack.config.js
module.exports = {
// ...
devServer: {
historyApiFallback: true,
},
};
Usage via CLI:
npx webpack serve --open --history-api-fallback
- The script should open
http://0.0.0.0:8080/
in your default browser. - You should see text on the page that reads
Current Path: /
. - Navigate to
http://localhost:8080/foo-bar
. - You should see text on the page that reads
Current Path: /foo-bar
.
Note: some URLs don't work by default. For example, if the url contains a dot (/file.txt
in this example).
Be sure to checkout the connect-history-api-fallback
options.
To allow /file.txt
to fallback, update the webpack.config.js
as follows:
webpack.config.js
module.exports = {
// ...
devServer: {
historyApiFallback: {
disableDotRule: true,
},
},
};
Use the following command to run the example:
npx webpack serve --open
- The script should open
http://0.0.0.0:8080/
in your default browser. - You should see text on the page that reads
Current Path: /
. - Navigate to
http://localhost:8080/file.txt
. - You should see text on the page that reads
Current Path: /file.txt
.