I have two routes with a different path
and name
but with the same component
. Is there a way to check what the path is when I navigate for ex. to /add-user
OR the name
for ex. AddUser
Routeconfig
app.component.ts
@RouteConfig([
{
path: '/add-user',
name: 'AddUser',
component: UserComponent
},
{
path: '/user/:id/detail',
name: 'UserDetail',
component: UserComponent
}
])
Update
Usercomponent
user.component.ts
ngOnInit() {
//this is pseudocode
if (this._router.name == 'AddUser') {
console.log('you want to add a user')
}
else{
console.log('you want to see the details of a user');
}
>= Angular2 RC.0 <= RC.3
There are no aliases anymore in the new router.
You can get the relative route of the local component
or the full path using
or
See also Angular2 get current route's alias
What you are looking for is:
router.currentInstruction.component.routeName
Small disclaimer: The new new router introduced in Angular 2.0 RC does not support route names. You might want to avoid using it.