路由器 3.0.0-rc.1 上的 Angular2 routerOnActivate

Angular2 routerOnActivate on router 3.0.0-rc.1

我使用 Angular2 RC.4 和 Router3 rc.1。

如何实施 routerOnActivate

import { OnActivate  } from '@angular/router';

报错模块没有exoprted成员。

这还没有完全实现,因为它是发布的目标,文档似乎有点超前。如前所述 here

In my opinion this is the most critical piece of functionality missing from Angular 2.0 today. I was able to get by using @brandonroberts OnActivate workaround, but now that it's gone in the release candidate I'm feeling a little high and dry here! I hesitate to use a third party solution like ngrx/router or ui-router so early in the life of this project.

由于 ngconf,我猜 rc 有点过早。

甚至 ngconf 的 @brandonroberts 研讨会也没有涉及在加载路由之前解析数据,因为新路由器中尚不存在该机制。

你能用守卫代替吗?今天这些对我来说非常好。

您无需导入任何内容即可使用 routerOnActivate()。在您的组件中,您可以像使用 ngOnInit(){} 函数一样直接使用 routerOnActivate(){}

export class DummyComponent() {
  
  ngOnInit() {
    // Do somehting here
  }
  
  routerOnActivate() {
    // Do something else here
  }
}