Questions tagged [angular-router-guards]

To find more information :

289 questions
2
votes
1 answer

canDeactivate() is not triggered on page navigation in Angular 8

I have a requirement of throwing a popup to the user when navigating to different component from the current component. And based on the input from the user i will have to either have to allow him to navigate away or make him stay. After a lot of…
2
votes
0 answers

Angular 8 - Get lazy loaded children to check canActivate while logout

I am on Angular 8. I have routing module setup as below. { path: '', redirectTo: 'ads', pathMatch: 'full' }, { path: 'ads', loadChildren: () => import('./ads/ads.module').then(m => m.AdsModule) }, { path: 'user', loadChildren: () =>…
2
votes
1 answer

Angular async requests when reloading page from browser

I've tried looking for solutions and most people suggest having a resolver, but in my case I think it would be too complicated so I really need advice on how to do this. Overview of the app: I have a platform that allows users to login…
2
votes
5 answers

Angular get matched url path in Guard

my routing is { path:'contacts/:id', component: contactDetail } in canActivateChild( route: ActivatedRouteSnapshot, state: RouterStateSnapshot) { console.log(state.url); } state.url return /contacts/1 what I need is matched url /contact/:id…
2
votes
1 answer

Role based redirection in Angular 6+

In my Angular8 app, there are 2 dashboard pages for User and Admin and I want to load the corresponding dashboard by using the role of a user to the PanelComponent. I think to use ngIf in the PanelComponent.html and load the corresponding dashboard…
2
votes
0 answers

How to handle uriParam before ngAfterViewInit?

I try to pass information from one website to another. The two websites do not share the same url or server. I have the idea that the best way is to use the URL parameters (http://some.url?param=value). So if I'm not mistaken in the Angular life…
2
votes
1 answer

How to make canActivate to wait for store loading

I'm trying to implement a guard in my project, that should wait until ngrx-store's loading complete and after this check is user authenticated or not. The problem, that guard doesn't wait completion of store's loading. My…
AnnaKoval
  • 21
  • 1
  • 4
2
votes
1 answer

Angular guards not working in the routing of pages

I'm working in the login of an app and I've created 2 guards for the routing of pages that should go after and before the login. The method I'm calling inside the CanActivate throws exactly what I want. true if the access_token exists and false if…
2
votes
1 answer

Angular ngrx: guards with side-effect

I have guard and now I need to catch error in it from a side-effect which calls an http service and redirects the user to an error state. I tried to add catchError, but I don't even go there if I get an error from server…
hofshteyn
  • 1,272
  • 4
  • 16
  • 33
2
votes
0 answers

CanDeactivate Route Guard Shows the selected route as active even when clicked on the cancel button

I am new to Angular and I also searched for the issue on the internet and could not find a solution. Can anyone please help me? This is so important for me. I have implemented a can deactivate route guard which triggers when we navigate to some…
Amit
  • 167
  • 1
  • 2
  • 14
2
votes
1 answer

Angular 6: Cannot get data from route resolver

I have a route configuration which allows a user to view the recent activities that has been done based on a criteria like so : { path: 'workspace', component: WorkspaceComponent, children: [ { path: 'upload', component: UploadComponent }, { path:…
Ka0s
  • 21
  • 3
2
votes
2 answers

Why CanDeactivate Guard Can't read a method in my component?

I am loading my routes lazily. I am trying to use CanDeactivate as per the documentation but it seems that the guard can not read the component's properties or methods. This is my guard, @Injectable() export class CanDeactivateGuard implements…
JSON
  • 1,583
  • 4
  • 31
  • 63
2
votes
1 answer

Angular 5: Conditionally Set Default Route

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…
NoRyb
  • 1,472
  • 1
  • 14
  • 35
2
votes
1 answer

Angular 5 lazy loaded module path overlays each others

I have an application with two lazy loading modules. Main module: const appRoutes = RouterModule.forRoot([ {path: '', redirectTo: '/welcome', pathMatch: 'full'}, { path: 'guest', loadChildren:…
2
votes
2 answers

Angular routing "opens" new page on top of the previous one and keep stacking in every route action

So i have an angular4 app using import {RouterModule, Routes } from '@angular/router' my routes config is set up like that : const appRoutes: Routes = [ {path: '', redirectTo: 'home', pathMatch: 'full',canActivate: [AuthGuard]}, {path:'login',…