angular-router-guards

Returning an Observable<boolean> from canActivate method and redirect on false

南笙酒味 提交于 2019-12-11 18:05:32
问题 I have been searching for a solution with no luck. I need to call the server if a user is authorized and i need canActivate method to wait for the result for that call. But i can`t seem to put pieces together. Below is my code, my question is in the comments of the code. canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): Observable<boolean> { let user: EUser = new EUser(); user.sessionId = localStorage.getItem("sessionId"); //I am not sure how to implement this part. // I

Routing to a specific page within a lazy-loaded module in angular 2+

和自甴很熟 提交于 2019-12-11 02:29:48
问题 I have the following in my main app router: { path: 'users', loadChildren: 'app/modules/users/users.module#UsersModule', canLoad: [AuthGuard] } When the user goes to http://localhost:4200/users/1234 to see their profile, I try to save the full url (including the user ID above) so that I would route back to that page once they're logged in. The problem is, the Route parameter in the canLoad function only has a path field that does not include the user ID above, only the path users . Is there a

Execute Multiple Asynchronous Route Guards in Order

▼魔方 西西 提交于 2019-12-07 16:42:52
问题 I know angular route guards execute in the specified order when the canActivate function returns a simple boolean , however, what if the guards return type Observable<boolean> or Promise<boolean> ? Example in route: { path: 'confirm', canActivate: [AuthGuard, SessionExpiredAuthGuard, CheckoutAuthGuard], component: CheckoutReviewOrderComponent }, SessionExpiredAuthGuard and CheckoutAuthGuard both return type Observable<boolean> . I don't want the CheckoutAuthGuard to be executed before the

Execute Multiple Asynchronous Route Guards in Order

耗尽温柔 提交于 2019-12-05 21:02:17
I know angular route guards execute in the specified order when the canActivate function returns a simple boolean , however, what if the guards return type Observable<boolean> or Promise<boolean> ? Example in route: { path: 'confirm', canActivate: [AuthGuard, SessionExpiredAuthGuard, CheckoutAuthGuard], component: CheckoutReviewOrderComponent }, SessionExpiredAuthGuard and CheckoutAuthGuard both return type Observable<boolean> . I don't want the CheckoutAuthGuard to be executed before the SessionExpiredAuthGuard is finished retrieving it's data from the asynchronous http request. Is there any

Angular CanDeactivate Router Guard with an Observable Subscribed Value

喜夏-厌秋 提交于 2019-11-28 13:52:39
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) { this.savingModelDataSource.next(state); } } My guard goes as import { Injectable } from '@angular