Angular2 Component does not reinitialize a parameterized route

I have below a test route with parameter T1:

{
    path: 'Test/:T1',
    component: TestComponent
},

When I head to "Test / 2" from "Test / 1", mine TestComponentdoes not reinitialize. Is this a problem with angular router?

I use "@angular/router": "3.0.0-beta.1"

+4
source share
2 answers

This is currently the only supported behavior. It is planned to make this configuration https://github.com/angular/angular/issues/9811

You can subscribe to change the parameters and perform initialization there

export class MyComponent {
    constructor(private route : ActivatedRoute,
      private r : Router) {}

    reloadWithNewId(id:number) {
        this.r.navigateByUrl('my/' + id + '/view');
    }

    ngOnInit() {
      this.sub = this.route.params.subscribe(params => {
         this.paramsChanged(params['id']);
       });
    }

    paramsChanged(id) {
      console.log(id);
      // do stuff with id

    }
}

See also How to manually render manually?

+2
source

2 , .

window.location.href = '/my/' + new_id_param + '/view';

, , , url .

" ", .

+1

Source: https://habr.com/ru/post/1650646/


All Articles