Skip to content

Latest commit

 

History

History

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 

README.md

historyApiFallback Option

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

What Should Happen

  1. The script should open http://0.0.0.0:8080/ in your default browser.
  2. You should see text on the page that reads Current Path: /.
  3. Navigate to http://localhost:8080/foo-bar.
  4. 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

What Should Happen

  1. The script should open http://0.0.0.0:8080/ in your default browser.
  2. You should see text on the page that reads Current Path: /.
  3. Navigate to http://localhost:8080/file.txt.
  4. You should see text on the page that reads Current Path: /file.txt.