Solvedangular Route throws 404 error when refreshed
✔️Accepted Answer
From what @robwormald said
This has nothing to do with Angular, per se - if you refresh the page, the request goes to the server before angular is even in the picture, so your server has to handle the request - typically it should just serve the index.html page for all routes, and then angular's routing will take over.
so i created a .htaccess code for that and its working fine.
@liongoncalves you can use the following .htaccess code
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(.*) /index.html [NC,L]
Other Answers:
Note that if you're using a simple server such as "http-server" or even something like "wamp" without any configuration, the problem is normal. Indeed, when you access the homepage, your "index.html" is automatically loaded, but if you access something like "http://url/part1", the server will look for a folder "part1" that contains an "index.html" page => error 404.
If this is indeed the issue you have, I would advise you to use "lite-server" which redirect redirect to "index.html" without any configuration.
What steps should we try in your demo to see the problem?
Go to any route different form home and refresh
Current behavior
When you are on any route different from / (for example /home, /products/1234) and you refresh the page, a 404 error appear.
Expected/desired behavior
It should go to the route.
Other information
I think i because de new Router comes with the HTML5 mode enable by default, but I'm trying to switch back to the HashLocation mode and I simply can't. And well the documentation is way out of date.