no-candeactivate-class
August 20, 2026 · View on GitHub
Restrict the usage of CanDeactivate which was the way to declare a legacy class-based guard.
Use CanDeactivateFn with a functional guard instead.
Documentation
Configuration
- in the
recommendedpreset - in the
functionalpreset - or just this rule:
{
rules: {
'eslint-plugin-angular-modern/no-candeactivate-class': 'error'
}
}
Tip
See the README for the global and presets configuration.
❌ Invalid
@Injectable({
providedIn: 'root',
})
export class UnsavedFormGuard implements CanDeactivate<SomeComponent> {
canDeactivate(): boolean {
return true;
}
}
✅ Valid
export const unsavedFormGuard: CanDeactivateFn<SomeComponent> = () => {
return true;
};