I've got an Angular 10 app which has to be called with an initial query parameter:
http://localhost:4200/?initialqueryparam=somevalue
I'm using hash location strategy, so further routes are like this:
http://localhost:4200/#/subroute/...?optionalqueryparamforspecificroute=anothervalue
What I need is to keep the initial query params for all further routes in the application. The url therefore should look like this:
http://localhost:4200/?initialqueryparam=somevalue/#/subroute/...?optionalqueryparamforspecificroute=anothervalue
Is this possible and if yes: how?
Update 1:
In the meantime I've implemented this hack using ngrx store. The disadvantage is, that the query params are not added after the base url but after the subroute:
http://localhost:4200/#/subroute/...?optionalqueryparamforspecificroute=anothervalue&initialqueryparam=somevalue
This has two disadvantages:
- My menu items which are styled with the help of the
routerLinkActive
directive are not styled correctly anymore because the configured route is not recoginzed due to the appended query param - When Right-Clicking on a menu item (browser context menu opens) and selecting "open in new tab" the query params get missed as the ngrx effect is not called in this case
- When calling the app with this url, I cannot use
window.location.search
like I do with the initial url to get the initial query param but I have to dig out the queryparam fromwindow.location.hash
with ugly string splitting.
It would be much better if there was a way to add the initial param directly behind the base url. Any ideas?