0

Angular build is hosted in the server and is working properly, except, on refreshing any of the page, it goes to web server 404 page.

While searching for the solution, everybody suggests the HashLocationStrategy. Is there any other way to resolve this so that the hash symbol will not appear in the url.

Webserver: Apache.

Note: One solution is to use .htaccess to redirect the 404 error response to angular build's index.html, But in this case the account activation lik clicked from the registered mails also will go to the index.html

Thanks in advance.

Sanjay Kumar N S
  • 4,653
  • 4
  • 23
  • 38

1 Answers1

2

Enable the rewrite engine in apache. You can enable it by below command

**sudo a2enmod rewrite**

Add below content to the .htaccess file.

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} -s [OR]

RewriteCond %{REQUEST_FILENAME} -l [OR]

RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]

RewriteRule ^(.*) /index.html [NC,L]

It will resolve the routing issue, You can redirect to the Home or index component when there is no route in your application from angular routes but writing 404 error document page and redirect to index.html is not good.

vJyOtaku
  • 81
  • 4