CanDeactivate在Angular2中不起作用

时间:2016-07-05 16:27:12

标签: typescript angular

我使用Angular 2 RC.4和新的Router(3.0.0-alpha.8)。 router-deprecated提供OnDeactivate接口,一个函数实现它在组件被停用时被调用。但是新路由器不支持OnDeactivate接口,但我们可以使用CanDeactivate接口。

我想在用户移动到其他页面(停用当前组件)时创建一个组件来输出消息,但CanDeactivate不起作用。

// app.components.ts
import { CanDeactivate } from '@angular/router';
...
export class AppComponent implements CanDeactivate<any> {
  canDeactivate(): boolean {
    // When users move to other pages, this component should output "foo" message.
    // But it does not work...
    console.log('foo');
    return false;
  }
}

0 个答案:

没有答案
相关问题