Easiest way to append new parameters to current URL in Angular

Discussão em 'Angular' iniciado por Jake11, Março 27, 2025.

  1. Jake11

    Jake11 Guest

    When navigating from menu I get route which looks similar to this

    www.address.com/verification/tasks

    and the view under this URI contains table, which has active routing so for that purpose in URL there are 2 parameters: page, limit

    www.address.com/verification/tasks/{page}/{limit}

    where page or limit is changed after doing some operations on view such as chaning pagination, filters etc.

    I need those params( page&limit ) to be set onInit if URL doesn't contains them yet, so I done this that way:

    ngOnInit(): void {
    const route = this.route.snapshot;

    if (!route.params.page || !route.params.limit) {
    this.router.navigate([
    '/verification/tasks',
    (route.params.page ? route.params.page : 1),
    (route.params.limit ? route.params.limit : 10)
    ])
    .then(()=>{
    this.loadFiltersData();
    })} else {
    this.loadFiltersData();
    }

    }


    as route.url[0] was only route.url entry and route.url[0].path was returning tasks without previous verification i had to hardcode that and don't feel thats the way it should be done.

    Continue reading...

Compartilhe esta Página