Reputation: 1452
I am using AngularDart and I am trying to set up a route so that I can get notified when the user clicks back from /user/1
to /user
.
I am only getting the print message out when I go from /user -> /user/1
but nothing when /user/1 -> /user
. I would have expected to get the "Show list of users" messages but the enter event doesn't fire
class RouterExample {
void call(Router router, ViewFactory views) {
views.configure({
'users': ngRoute(
path: '/user',
enter: (_) {
print('Show list of users');
},
leave: (_) {
print('Hide list of users');
},
mount: {
'view' : ngRoute(
path: '/:id',
enter: (_) {
print('Show a user');
},
leave: (_) {
print('Hide user');
}
)
}
)
});
}
}
Upvotes: 3
Views: 90
Reputation: 76193
Basically your users
route is still active when you go from /user/1
to /user
.
To handle list as you want you should define another mount entry :
class RouterExample {
void call(Router router, ViewFactory views) {
views.configure({
'users': ngRoute(
path: '/user',
mount: {
'view' : ngRoute(
path: '/:id',
enter: (_) => print('Show a user'),
leave: (_) => print('Hide user')
),
'list': ngRoute(
path: '',
enter: (_) => print('Show list of users'),
leave: (_) => print('Hide list of users')
)
}
)
});
}
}
Upvotes: 3