I have an angular project which has multiple routes say /category/fruit/apple
so the full url is http://myserver/category/fruit/apple
through router link everything is fine but if I open this link directly in typing in URL then it is 404
my backend is nodejs with express. And the 404 make sense as there is no route configured like this.
My Question, In this kind of situation how should I handle?
I thought I had, redirect to root http://myserver?path=category-fruit-apple and from the root component do the dynamic routing. Is it the correct way ?
Please suggest the best way.
There is a frontend-only solution (so, zero configuration server-side), too, namely hash routing. Add a line
useHash: true
in the root router module's configuration (then, the urls will look something like http://myserver/#/category/fruit/apple
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With