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.

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your response. This is worked for the main routing like dashboard,But for the inner routing like users/scadmin is not working.
It will work for inner routes also..do hav any authguards etc..in ur route..? can you tell wht was the error getting for inner routes..?
It's throwing 404 itself

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.