import { Injectable } from '@angular/core' ; import { CanActivate , Router , ActivatedRouteSnapshot , RouterStateSnapshot , CanLoad , Route } from '@angular/router' ; import { WorkflowService } from './workflow.service' ; @ Injectable ( ) export class WorkflowGuard implements CanActivate { constructor ( private router , private workflowService ) { } canActivate ( route , state ) { let path = route . routeConfig . path ; return this . verifyWorkFlow ( path ) ; } verifyWorkFlow ( path ) { console . log ( "Entered '" + path + "' path." ) ; let firstPath = this . workflowService . getFirstInvalidStep ( path ) ; if ( firstPath . length > 0 ) { console . log ( "Redirected to '" + firstPath + "' path which it is the first invalid step." ) ; let url = `/${ firstPath }` ; this . router . navigate ( [ url ] ) ; return false ; } ; return true ; } }