Question

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');
                    }
                )
            }
        )
    });
  }
}
Was it helpful?

Solution

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')
          )
        }
      )
    });
  }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top