I have an app that uses HashLocationStrategy and I want to change it to PathLocationStrategy. The issue is that I don't want to break existing links (ie bookmarked by users).
The main idea is to receive urls like localhost:3002/#/crisis-center and redirecting to localhost:3002/crisis-center
How can I configure this apart from removing useHash from the code below?
RouterModule.forRoot(routes, { useHash: true })
I think this link has the quick answer you are looking for.
Here is the code for it:
app.component.ts
But I think if you have access to the web server, you should do a redirect there instead. That's because with this front-end solution, it will only work if and only if the
app.componentstay alive the entire time. It is possible that it might get destroyed. I added theconsole.login thengOnDestroylife cycle hook. You should test your application to see if this will ever get called.