Search code examples
angularserverrouteslive

Can not get /route after refresh page Angular 7


I have a few components in Angular 7, and I don't use 'useHash: true' for routing.

I deployed my Angular app on live server, if I navigate to some component using routing (for example /panel) then it is working properly, but if I reload that page I get error 'Can not get /panel'

Could anyone help with this ?


Solution

  • You should configure your server to fallback to index.html. Check at angular docs here how you can do this. On Appcache server for example I am using this .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]