None
None

Reputation: 9247

How to remove specific param from url?

I have this route :

www.test.com/evidention?procesId=12&esid=12

I want to remove only this esid. Any suggestion how can i do that?

Upvotes: 3

Views: 14104

Answers (2)

Pavel Agarkov
Pavel Agarkov

Reputation: 3783

In the component or service where you want this deletion you can do the following:

export class ComponentOrService
{
    constructor(
      protected readonly route: ActivatedRoute,
      protected readonly router: Router
    ) { }

    deleteQueryParameterFromCurrentRoute()
    {
        const params = { ...this.route.snapshot.queryParams };
        delete params.esid;
        this.router.navigate([], { queryParams: params });
    }
}

PS: [] here means to stay on the same route and only change queryParams

Upvotes: 10

Mohammad Hassani
Mohammad Hassani

Reputation: 541

In angular 7+ there is error with "no provider for activatedroutesnapshot"

insteated you can use from ActivatedRoute

in constructor use

    private _ActivatedRoute: ActivatedRoute

and with this you can change url parameters

    var snapshot = this._ActivatedRoute.snapshot;
    const params = { ...snapshot.queryParams };
    delete params.esid
    this.router.navigate([], { queryParams: params });

Upvotes: 2

Related Questions