Refreshing a page in Angular project results in page not found error.

When you refresh a page in an Angular project, if you get the following error,

Not Found

The requested URL /pagename/ was not found on this server.

One of the ways to fix the issue is by adding a .htaccess file. The content of the file is as follows.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>

Note that there are other ways of solving the problem (by updating the code) but this has fixed the issue for us.

Leave a Reply

Your email address will not be published. Required fields are marked *