I have an Angular2 router (RC1) that loads the same component in all of its three routes:
@Routes([
{ path: '/create', component: MyComponent },
{ path: '/detail/:id', component: MyComponent },
{ path: '/update/:id', component: MyComponent },
])
The reason behind this is because I need three forms for CRUD actions that very similar to each other. So, I decided to use the same component combined with a few *ngIf
s based on the component mode (create, detail, update).
The problem now is that I can't find a way to get the name of the last segment on the URL. Ideally I could like to do something like this (pseudocode):
export class MyComponent {
constructor(private router: Router) {
this.mode = this.router.getLastURLSegmentName();
if (this.mode == 'detail' or this.mode == 'update') {
let param_id = this.router.getLastURLSegment().getParam('id');
}
}
}
How can I achieve such functionality? Any ideas? Thank you!