Question: Is it possible to change query params without reloading route?
See original GitHub issueI’ve got a strange use case - I’ve got a checkout form where user can select a product and enter a discount coupon. Now, whenever user changes a selected product, or enters a coupon, I’d like to persist this info in query parameters, so that when user reloads the page, or sends its url to someone else, they will see the page in exactly the same state. However, if I use navigation.navigate
(or history.push
) to change query params, it triggers route change and executes routing code again and I’d like to avoid that. Angular 1.x router has reloadOnSearch
option that could be set to false
, to avoid reloading route on query params change. Is it somehow possible to do the same thing with navi?
Issue Analytics
- State:
- Created 4 years ago
- Comments:5
Top Results From Across the Web
Angular: How to update queryParams without changing route
The Best Answer is ... You can navigate to the current route with new query params, which will not reload your page, but...
Read more >change route params without reloading browser in angular
I have face this problem when I kept my apps data in route param and that require to change (when user change apps...
Read more >Angular 6 add query params without reloading - iTecNote
You get the new query params by subscribing to queryParams changes For example: constructor( private activatedRoute: ActivatedRoute, ) { } this.activatedRoute.
Read more >Angular: Change the route without reloading - Medium
In order to update the route without a reload of the entire component (page) I had to resort to plain ol' JavaScripts replaceState...
Read more >Angular Basics: Using Query Params in Angular Routing
Today we will look at how we can pass query parameters to the URL of our app using the routing module in Angular...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve come across a similar problem so I definitely want to find a good solution for this. The issue is that HTTP redirects on the server can’t pass state through, and I want the API to work across both SSR and the client.
I have a few ideas about this, just need to find the time to put them into a proposal or some code.
One more use case 😉
We support PayPal payments and we need to pass a failure url that PayPal will redirect to in case of, well, failure. In our case the failure url is the same checkout page, where user initiates PayPal payment. We only append a query param with an error message to it and PayPal appends a
token
query param. In our old Angular app, we checked for these query params on page load, showed an error message and removed them. This way when user would e.g. reload the page, they wouldn’t see the same error message again. Because this logic happened in a component, we could already preselect PayPal as preferred payment when these query params were present.In navi, it looks like I can redirect to the same url without these query params, but then I won’t know that user had PayPal selected. Unless it’s possible to pass
state
toredirect
function, just like tonavigation.navigate
? Not a big deal, but would be useful to support this use case.