2

Is it possible to use CanDeactivate with a directive instead of a component?

My implementation is shown below, but doesn't work:

class CanDeactivateTeam implements CanDeactivate<SomeDirective> {

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

        return directive.doChecks();
      }
}

And my router:

export const myRouters: Array<any> = [
    {
        path: "",
        redirectTo: "something",
        pathMatch: "full",
    },
    {
        name: "somepath",
        path: "somepath",
        component: MyComponent,
        canDeactivate: [CanDeactivateTeam],
        ...
    }
}
raneshu
  • 363
  • 2
  • 16
  • 46

0 Answers0