You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Allow router configuration so that preserveQueryParams is true by default #12664
Currently the router allows an individual navigation to preserve the query params (eg. Google's common hl query param)
This feature request is to allow the router to be configured so that this behavior takes place for all navigation.
Reacted by Suguru Inatomi, Brian Michalski, Harold Saldanha, Michael Cornel, Quentin, dizzy, Igor Zupet, Matt Distefano, guduf, Elvis Begovic and 141 more
I'd also like to know. The workarounds listed on that stack overflow are for once you're already inside the application. There is no solution if your route into the application has a query parameter. The app strips it on app entry.
Reacted by Connel Hooley, SquadWuschel, Stan Silvert, 7im, Dominique Müller, Andriy Shafran, Justin Baker, TreNrod, Dominik König, Dan and 35 more
There is queryParamsHandling: 'preserve' on NavigationExtras which handles this for programmatic navigation but, I do not see a global level configuration. Without a global setting all the links embedded in the views would also need to be touched to add that config too right?
Reacted by Hari S, Tushar, Neil Ellis, Nahuel Soldevilla, _|+, Ryan Voronyak and Hassan Assaad
For what it's worth, I had filed a duplicate feature request earlier, which had some work done on it but was closed because it was deemed that a complete solution wasn't possible at the time, and not enough users needed such a thing. #16558
Reacted by Matmo10, SquadWuschel, Grzegorz Skoczylas, Andrey Kolkov and Nahuel Soldevilla
@karsunke i used your workaround and its great working until a user wants to go back via the back button of the browser.
Because the URL always just goes back to /foo/bar just to instantly change to /foo/bar?some=name again. I tried to do a workaround but its getting smelly. (workaround-workaround-workaround).
I need this global configuration of queryParamsHandling!
As noted in the linked issue #13315, you can keep the parameter if your redirectTo is not absolute. Then you can subscribe to the activatedRoute and get the query params-
and referenced the above function and I am still getting this weird behavior... Attached a small clip.
Screen.Recording.2023-10-03.at.9.47.27.AM.mov
Do you remove / update the part where i only keep the queryParams when the route match my home route ?
// if not on the home page juste do nothing and return
const urlToString = urlTree.toString();
if (!urlToString.includes(RoutePathFull.Home)) {
return urlToString;
}
I've struggled for hours with that too. None of the solution posted here matches exactly with my application. I've finally implement a mix of proposals and the result is like grandmother's medicine : effective but ugly.
A specific implementation of the hash location strategy that store the params (...)
@shyamal890 See #12664 (comment). It's quite unclear what developers are actually looking for in a solution here. The simple "solution" is easy and could be released if there were a clear signal that this is sufficient for the majority of people upvoting this issue. A more robust solution for query params alone can likely be achieved through existing APIs. Developing an entirely new feature for managing the query params would likely never be prioritized without overwhelming support.
I'm not sure if this is exactly the same issue for me, but it seems to be relevant. I'm using a Hash-based location strategy and I was seeing the index page, the path info, and the query-string of the host page being stripped-out. For example, if I landed on this resource:
However, this broke the <script> tag sources that were injected into the page. So, I also had to include a --deploy-url in my build script that prefixed all injected script src values to the right directory:
ng build --configuration production --deploy-url=/path/to/app/
The whole thing seems like a house-of-cards (possibly because I don't fully understand the routing configuration). It's unclear to me why any host URL alterations would take place at all when using Hash-based routing. It seems that Angular should only ever touch the fragment of the URL and nothing else.
angular-automatic-lock-bot commented on Sep 29, 2024
Activity
ssilvert commentedon May 3, 2017
Why was this closed? AFAICT, there is still no solution to this problem:
http://stackoverflow.com/questions/39898656/angular2-router-keep-query-string
mattrowsboats commentedon May 3, 2017
I'd also like to know. The workarounds listed on that stack overflow are for once you're already inside the application. There is no solution if your route into the application has a query parameter. The app strips it on app entry.
dan3721 commentedon Jul 17, 2017
There is queryParamsHandling: 'preserve' on NavigationExtras which handles this for programmatic navigation but, I do not see a global level configuration. Without a global setting all the links embedded in the views would also need to be touched to add that config too right?
karsunke commentedon Oct 10, 2017
I know that the angular team is busy as hell, but can we get at least a comment if this will be supported some time in the future?
My solution is to subscribe to the queryParameters and add them if they do not exist:
voithos commentedon Nov 21, 2017
For what it's worth, I had filed a duplicate feature request earlier, which had some work done on it but was closed because it was deemed that a complete solution wasn't possible at the time, and not enough users needed such a thing. #16558
Joniras commentedon Jan 5, 2018
@karsunke i used your workaround and its great working until a user wants to go back via the back button of the browser.
Because the URL always just goes back to /foo/bar just to instantly change to /foo/bar?some=name again. I tried to do a workaround but its getting smelly. (workaround-workaround-workaround).
I need this global configuration of queryParamsHandling!
chriszrc commentedon Jan 9, 2018
As noted in the linked issue #13315, you can keep the parameter if your redirectTo is not absolute. Then you can subscribe to the activatedRoute and get the query params-
Joniras commentedon Jan 9, 2018
My Issue has nothing to do with redirectTo. I dont use it anywhere in my project.
My Current Workaround for preserving query params in a global way ( from SO ):
And this is not a clean solution for me.
54 remaining items
smichel-amiltone commentedon Sep 28, 2023
I use this and provide the home path to do it only on this path !
app.module.ts
Class PreserveQueryParamsPathLocationStrategy
antoineaws commentedon Oct 3, 2023
Weird.. I did add the above location strategy to
app.module.tsin providers:and referenced the above function and I am still getting this weird behavior... Attached a small clip.
Screen.Recording.2023-10-03.at.9.47.27.AM.mov
smichel-amiltone commentedon Oct 3, 2023
Do you remove / update the part where i only keep the queryParams when the route match my home route ?
laurentgrenier commentedon Dec 13, 2023
I've struggled for hours with that too. None of the solution posted here matches exactly with my application. I've finally implement a mix of proposals and the result is like grandmother's medicine : effective but ugly.
A specific implementation of the hash location strategy that store the params (...)
Then, I read the params from where I use them:
I'm so sorry for state of the art :)
shyamal890 commentedon Jul 19, 2024
With so many people looking for a solution, an update on the following would really help us move in a particular direction:
atscott commentedon Jul 19, 2024
@shyamal890 See #12664 (comment). It's quite unclear what developers are actually looking for in a solution here. The simple "solution" is easy and could be released if there were a clear signal that this is sufficient for the majority of people upvoting this issue. A more robust solution for query params alone can likely be achieved through existing APIs. Developing an entirely new feature for managing the query params would likely never be prioritized without overwhelming support.
shyamal890 commentedon Jul 30, 2024
@atscott
defaultQueryParamsHandlingwould be great. We can then decide to remove query params we don't need in a particular route.feat(router): Add defaultQueryParamsHandling to router configuration (#…
bennadel commentedon Aug 29, 2024
I'm not sure if this is exactly the same issue for me, but it seems to be relevant. I'm using a Hash-based location strategy and I was seeing the index page, the path info, and the query-string of the host page being stripped-out. For example, if I landed on this resource:
/path/to/app/index.cfm/path/info?hello=world#/angular/routeMost of the resource information was being stripped out (presumably with a push-state) to become:
/path/to/app/#/angular/routeI was able to "fix" this by adding the entire "internal URL" to the
<base href>tag:<base href="/path/to/app/index.cfm/path/info?hello=world">However, this broke the
<script>tag sources that were injected into the page. So, I also had to include a--deploy-urlin my build script that prefixed all injected script src values to the right directory:ng build --configuration production --deploy-url=/path/to/app/The whole thing seems like a house-of-cards (possibly because I don't fully understand the routing configuration). It's unclear to me why any host URL alterations would take place at all when using Hash-based routing. It seems that Angular should only ever touch the fragment of the URL and nothing else.
angular-automatic-lock-bot commentedon Sep 29, 2024
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.