Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove specific param from url?

Tags:

angular

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?

like image 534
None Avatar asked Nov 19 '25 07:11

None


2 Answers

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

like image 175
Pavel Agarkov Avatar answered Nov 21 '25 08:11

Pavel Agarkov


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 });
like image 36
Mohammad Hassani Avatar answered Nov 21 '25 10:11

Mohammad Hassani