2

是否可以使用CanDeactivate指令而不是组件?

我的实现如下所示,但不起作用:

class CanDeactivateTeam implements CanDeactivate<SomeDirective> {

    canDeactivate(
        directive: SomeDirective,
        currentRoute: ActivatedRouteSnapshot,
        currentState: RouterStateSnapshot,
        nextState: RouterStateSnapshot
      ): Observable<boolean>|Promise<boolean>|boolean {

        return directive.doChecks();
      }
}

还有我的路由器:

export const myRouters: Array<any> = [
    {
        path: "",
        redirectTo: "something",
        pathMatch: "full",
    },
    {
        name: "somepath",
        path: "somepath",
        component: MyComponent,
        canDeactivate: [CanDeactivateTeam],
        ...
    }
}
4

0 回答 0