There are two important parts to solve this problem:
Solution Part 1. Set the “base-href” to the same sub directory that is inside of your “dist” directory.
Angular 8+ exports your application into a “dist/my-app-sub-directory”, notice there is now a sub directory inside “dist” (in previous versions of Angular your app was exported in “dist” directly, that’s not the case anymore). In order to fix this problem be sure you use the flag to configure the base-href as follows:
ng build --prod --baseHref=/my-app-sub-directory/
For a complete working example using multi-lingual configurations check this repository out.
In Nginx that can be done using a configuration such as this one in your server block:
See the full server block configuration file for Nginx here.
If you are looking for something just for development purposes Live Server + a custom middleware can do the job.
Check this example of a custom middleware. Run it with:
That’s it. See you next time!