0

I'm using nested routing in my Angular app, which works fine with routerLink. However, when I reload the page or type the URL manually, I get a 404 error.

I'm importing some dependencies in the index.html. Is it possible they are causing the problem?, and how can I fix it?

This is the error I get

iEmad00
  • 31
  • 3
  • How are you running the server? Local or deployed somewhere? – Phix Aug 01 '23 at 19:51
  • I run it locally – iEmad00 Aug 01 '23 at 19:55
  • With the angular cli or something else? Usually this means that the server isn't configured correctly, but it's hard to say without more information. – Phix Aug 01 '23 at 21:06
  • The problem is solved when I added providers: [{provide: LocationStrategy ,useClass: HashLocationStrategy}], to my app.module file, but it keeps adding # in the URL and I don't think it's a good solution, any ideas? – iEmad00 Aug 02 '23 at 16:22

1 Answers1

2

Finally, I solved the problem by using this code inside the main HTML file

<head>
  <base href="/">
  ...
</head>

For more information: Angular 2 router no base href set

I hope my post helps

iEmad00
  • 31
  • 3