上下文:我正在尝试将路由添加到angular2的TodoMVC实现中:https://github.com/ng2-dart-samples/todomvc

angular2的官方todomvc没有't have routing yet, so that doesn' t帮助:https://github.com/tastejs/todomvc/tree/gh-pages/examples/angular2

我一直在研究其他一些有角度的2路由示例 . 我理解他们将一些路径绑定到组件类的示例 . 但我想使用路由,主要过滤一个todolist中的一些元素,我不想将它绑定到一个完整的组件 . 所以我的问题是,这可能吗?

我可以用一点点hacky方式实现它:

@RouteConfig(const [
  const Route(path: '/', component: TodoComponent, as: 'all'),
  const Route(path: '/active', component: TodoComponent, as: 'active'),
  const Route(path: '/completed', component: TodoComponent, as: 'completed'),
])
class App {}

然后监听子组件中的更改:

class TodoComponent {
  Router router;
  String filter;
  TodoStore todoStore;

  TodoComponent(this.todoStore, this.router) {
    router.parent.subscribe((String value) => filter = value);
  }
}

我希望有更直接的方法来做到这一点 . 例如,一些代码如下:

@RouteConfig(const [
  const Route(path: '/'),
  const Route(path: '/active'),
  const Route(path: '/completed'),
])
class TodoComponent {
  Router router;
  String filter;
  TodoStore todoStore;

  TodoComponent(this.todoStore, this.router) {
    router.subscribe((String value) => filter = value);
  }
}

但这不起作用 . 任何其他选择 . 或者这样的事情还没有实现呢?