Schlagwort-Archive: AngularJS

Publish Angular2-App using Webpack

$ npm run build:prod

This creates a folder called dist. This folder has to be copied to the webserver. I ran into the issue that an error appeared on reloading a page.

I’m not using the hash for routing ({useHash: false}), so all links appear as real paths like ibse-fehse.de/services.
But so reloading a sub-page leads to a 404-server-error „Page not found“ because the current path could not be located server-side.
Solution is to add some lines to .htaccess:

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]
# If the requested resource doesn't exist, use index.html
RewriteRule ^ /index.html

Thanx to Dan Mindru.