-1

I have this two path:

{ path: "evidencija/:type/:specId/:activeIndex", component: VpnEvidencijaFlowComponent },
  { path: "evidencija/:type/:offerId/:specId/:activeIndex", component: VpnEvidencijaFlowComponent },

In ts i have this:

 this.router.navigate(['/evidencija', this.type, children.key, 0], {queryParams: this.queries});

Problem is that i get all of this params but it set undefined on place where should be offerId but i dont have it in some cases. Any suggestion why do i get undefined in url ?

None
  • 8,817
  • 26
  • 96
  • 171

1 Answers1

0

The problem is your route, you don't have to define param in you path.

he must just associate a name with a route (and therefore a page)

If you want pass param in you route, you need to use navigate like this :

 this.router.navigate(['/evidencija', this.type, children.key, 0]);

and you path is just :

 { path: 'evidencija', component: VpnEvidencijaFlowComponent},

And for read your param in the other component import :

import { ActivatedRoute } from '@angular/router';

Declare it in contructor :

private route: ActivatedRoute

And get your param in NgInit :

  ngOnInit() {
    this.sub = this.route.params.subscribe(params => {
       this.id = params['id'];
    });
  }
Léo R.
  • 2,620
  • 1
  • 10
  • 22