Skip to content

CanDeactivateGuard

reference
1 min readUpdated

Kind: Class

Source: Frontend/src/app/pipes/CanDeactivateGuard.ts (line 12)

Part of: Frontend

CanDeactivateGuard determines whether a route or view can be deactivated. Its canDeactivate() method returns a boolean that calling code can use to allow or block navigation away from the current state.

Methods

MethodSignatureReturns
canDeactivatecanDeactivate(component: ComponentCanDeactivate, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState: RouterStateSnapshot)boolean

Diagram

mermaid
graph LR
  A[Navigation request] --> B[CanDeactivateGuard]
  B --> C[canDeactivate()]
  C --> D{Boolean result}
  D -->|true| E[Allow deactivation]
  D -->|false| F[Block deactivation]

Usage

ts
import { CanDeactivateGuard } from './pipes/CanDeactivateGuard';

const guard = new CanDeactivateGuard();

if (guard.canDeactivate()) {
  // Continue with navigation or cleanup.
} else {
  // Keep the current view active.
}

AI Coding Instructions

  • Keep canDeactivate() returning a boolean so callers can make a direct allow-or-block decision.
  • Update navigation integration when changing the guard's deactivation behavior.
  • Avoid adding side effects to canDeactivate() unless the calling flow expects them.
  • Test both true and false outcomes in code that depends on this guard.

Used by

26 references from 26 files. Each is a place in this repository where the symbol is actually used — go read one rather than trusting an example.

Imported by (26)

  • AppRoutingModuleFrontend/src/app/app-routing.module.ts:1
  • TranslateHandlerFrontend/src/app/app.module.ts:1
  • MrqModuleFrontend/src/app/components/MRQ/mrq.module.ts:1
  • BlogsModuleFrontend/src/app/components/blogs/blogs.module.ts:1
  • ConfigurationRoutingModuleFrontend/src/app/components/configuration/configuration-routing.module.ts:1
  • ActivitiesRouteModuleFrontend/src/app/components/dashboard/activities-route.module.ts:1
  • DashboardModuleFrontend/src/app/components/dashboard/dashboard.module.ts:1
  • TasksRouteModuleFrontend/src/app/components/dashboard/tasks-route.module.ts:1

…and 18 more.

Was this page helpful?

Download as PDF