angular-router-guards

Angular 4 Multiple Guards - Execution Sequence

时光毁灭记忆、已成空白 提交于 2020-08-27 01:34:41
问题 I have 2 guards, AuthGuard and AccessGuard in the application. AuthGuard protects all the pages as the name suggests and stores the session object in the GlobalService and AccessGuard depends on the some access data in session object stored by AuthGuard in GlobalService. Problem arises when AuthGuard returns an Observable and then simultaneously AccessGuard executes to check for session object which has not yet arrived and the code breaks. Is there any other way I can restrict the execution

TypeError: Cannot read property 'canDeactivate' of null

╄→гoц情女王★ 提交于 2020-07-22 05:31:10
问题 I'm trying to use the canDeactivate router guard. The component I'm passing in (ClaimsViewComponent) is null the first time the code runs. But on subsequent runs, the code runs as expected. We're trying to figure out why the component is null on first run. This is the canDeactivate guard code: @Injectable() export class ConfirmDeactivateGuard implements CanDeactivate<ClaimsViewComponent> { canDeactivate(target: ClaimsViewComponent): boolean { if (target.canDeactivate()) { return window

How to send return value to CanDeactivate Guard after close the mat-dialog | Angular CanDeactivate Guard | Angular Material Dialog

可紊 提交于 2020-03-03 11:45:11
问题 I'm using CanDeactivate Guard for find out the unsaved changes and If changes occurred I am showing the confirm material dialog, before leaving the page. Based on the dialog action I will return the Boolean value. CanDeactivateGuard.ts: export class DeactivateGuard implements CanDeactivate<UnsavedChangesComponent> { canDeactivate( component: UnsavedChangesComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): boolean | Observable

How to send return value to CanDeactivate Guard after close the mat-dialog | Angular CanDeactivate Guard | Angular Material Dialog

你离开我真会死。 提交于 2020-03-03 11:45:09
问题 I'm using CanDeactivate Guard for find out the unsaved changes and If changes occurred I am showing the confirm material dialog, before leaving the page. Based on the dialog action I will return the Boolean value. CanDeactivateGuard.ts: export class DeactivateGuard implements CanDeactivate<UnsavedChangesComponent> { canDeactivate( component: UnsavedChangesComponent, currentRoute: ActivatedRouteSnapshot, currentState: RouterStateSnapshot, nextState?: RouterStateSnapshot): boolean | Observable

Angular 5: Conditionally Set Default Route

拜拜、爱过 提交于 2020-01-23 03:46:06
问题 I have a navigation with three submenus and their according children routes. Now some of the submenus are not visible (ngIf), depending on the claims a user got from the server. Wenn the main menu is clicked, I redirect to one of the submenus but sometimes this submenu is not accessible - then I would like to redirect to the next sibling: { path: 'mymainmenue', children: [ { path: 'submenu1', component: SubMenu1Component }, { path: 'submenu2', component: SubMenu2Component }, { path: 'submenu3

How to elegantly get full url from the ActivatedRouteSnapshot?

…衆ロ難τιáo~ 提交于 2020-01-02 00:50:13
问题 in some of my angular route guards, I want to set up the "next" path, to redirect to after successful login. So, the oridinary guard canActivate function signature looks like this: public canActivate(route: ActivatedRouteSnapshot): Observable<boolean> | boolean { // ...blah return true; } The route parameter is an instance of ActivatedRouteSnapshot. Previously to get the "next" URL I was just getting it from the route.url . This works just fine, as long as there are no children routes. My

Angular 4 CanActivateChild doesn't work

痞子三分冷 提交于 2019-12-24 07:25:31
问题 I'm trying to restrict access to my route system using CanActivateChild , however when I try to prevent user's navigation to a set of child states, the RouteGuard doesn't work, only on CanActivate . This is my routing module: export const routes = [ { path: "", redirectTo: "/signin", pathMatch: "full" }, { path: "signin", component: SigninComponent }, { path: "user", component: UserComponente, canActivate: [AuthGuard], canActivateChild: [AuthGuard], children: [ { path: "profile", component:

Angular CanDeactivate Router Guard with an Observable Subscribed Value

社会主义新天地 提交于 2019-12-17 21:32:05
问题 I've been trying to write a canDeactivate guard to check a saving state from an observable stream and work accordingly. My service goes as this import { Injectable } from '@angular/core'; import { ReplaySubject } from 'rxjs/ReplaySubject'; import { Observable } from 'rxjs/Observable'; @Injectable() export class EditModelService { private savingModelDataSource = new ReplaySubject<boolean>(); savingModelData$ = this.savingModelDataSource.asObservable(); public setSavingModelData(state: boolean)