I have an angular 2 application, and I use a router to navigate between views, like everyone else. Here's what my path to a specific component looks like:
{ path: 'home/view1/:viewID', component: ViewComponent, children: [ { path: 'pane/:paneId/section/:sectionId', component: SectionEditComponent }, { path: '**', component: ViewEditComponent } ] },
Now I have two buttons on the ViewComponent to load the EditComponent section for section1 and section2.
Path 1: panel / 1 / section / 1
Path2: Panel / 1 / Section / 2
ViewComponent Template:
<div class="col-md-8" style="background-color: white; height: 100%"> <button (click)="loadPath(1)">Path1</button> <button (click)="loadPath(2)">Path2</button> <router-outlet></router-outlet> </div>
Now when I navigate from Path1-> Path2 or Path2-> Path1 within the same ViewComponent, ngOnInit () is not called, so it doesn’t load the new path, even if the URL does change to match the new section identifier.
Is this known or expected behavior? Is there something I'm doing wrong?
angular angular2-routing
Sanjay verma
source share