0

I am trying to update query params using router navigate

updateURL(queryParams){
        this.router.navigate(['path], {
            relativeTo: this.route,
            queryParams: queryParams,
            queryParamsHandling: 'merge',
            skipLocationChange: false
        });
}

/** Wont Work 
updateURL(queryParams);
updateURL(queryParams);
updateURL(queryParams);

/** Will Work
updateURL(queryParams);
// wait
updateURL(queryParams);
// wait
updateURL(queryParams)

When sequential calls are made to this method to update URL query params, angular does not update url. How it can be handled so that angular updates url even when sequential calls are made

1 Answer 1

1

from docs it is promise you will have to wait to fire next update

navigate(commands: any[], extras: NavigationExtras = { skipLocationChange: false }): Promise<boolean>

Can you try this

async updateURL(queryParams){
       await this.router.navigate(['path], {
            relativeTo: this.route,
            queryParams: queryParams,
            queryParamsHandling: 'merge',
            skipLocationChange: false
        });
}

async UpdateQueryParam() {
 await updateURL(queryParams);
  await updateURL(queryParams);
  await updateURL(queryParams)
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.