Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Configuring the Webpack Dev Server for Angular html5mode

I'm trying to enable html5mode in an Angular 1 application. This mode requires the webserver to return the same HTML for various paths. In nginx, this is done by adding a try ... index.html for the location, meaning nginx always fails back to the main html if it can't find the page.

However, while development I have no nginx, I'm using the Webpack dev server to serve the pages, with a proxy to the backend. How do I configure the Webpack dev server to behave in a similar fashion?

like image 336
zmbq Avatar asked Mar 06 '17 07:03

zmbq


1 Answers

Oh dear. Oh dear oh dear oh dear.

I scanned the documentation twice, and only after posting this question I found the historyApiFallback settings, as described here.

Add this to the settings:

devServer: {
    historyApiFallback: true,
    proxy: { ... }
}

I'm keeping this question here hoping it will help others save time in the future.

like image 186
zmbq Avatar answered Oct 03 '22 03:10

zmbq