[Fixed] How to change queryParams without triggering subscribe?

Issue

Hi building angular app with multi routes.

Navigate to a page > queryParams trigger the subscribe.

when im in the page i need change the queryParams inside the page but not to trigger the subscribe function again. (because i dont want the data to reload again because i have already the data when i navigate to the page,i want only to change the params without trigger subscribe so if the user hit refresh the page will reload with the correct url and the subscribe function will work as a new navigation to the page)

i know i can use snapshot but im preferring using optional attributes.

and ideas?

Solution

when im in the page i need change the queryParams inside the page but not to trigger the subscribe function again.

One solution would be to, inside the component, subscribe not to query params, but only to the first emitted value:

const mySubscription = this.activatedRoute.queryParams // or queryParamMap
    .pipe(
        take(1)
    )
    .subscribe(//...

Leave a Reply

(*) Required, Your email will not be published