no-canmatch-class

August 20, 2026 · View on GitHub

Restrict the usage of CanMatch which was the way to declare a legacy class-based guard.

Use CanMatchFn with a functional guard instead.

Documentation

Configuration

  • in the recommended preset
  • in the functional preset
  • or just this rule:
{
  rules: {
    'eslint-plugin-angular-modern/no-canmatch-class': 'error'
  }
}

Tip

See the README for the global and presets configuration.

❌ Invalid

@Injectable({
  providedIn: 'root',
})
export class AuthGuard implements CanMatch {
  canMatch(): boolean {
    return true;
  }
}

✅ Valid

export const authGuard: CanMatchFn = () => {
  return true;
};

Back to README