Skip to main content
1 vote
1 answer
79 views

How do I apply the `canActivateFn` to all routes in a standalone Angular application?

In module-based applications, to add a guard to all routes at once, i can pass it as the second parameter to the RouterModule.forRoot function. RouterModule.forRoot(routes, { canActivate: [AuthGuard] }...
Vlad's user avatar
  • 26
1 vote
3 answers
215 views

unable to perform CanDeactivateFn Karma Test Angular 16

I have a canDeactivateGuard which returns from component's MatDialog for unsaved action. My problem is I am unable to test the functional guard and getting error - TypeError: Cannot read properties of ...
ufccoder's user avatar
1 vote
0 answers
90 views

Angular route guards - redirection/refresh loop on Firefox

I have this route guard that returns an observable, which checks for certain conditions before either: activating navigation redirecting somewhere outside the app redirecting to an internal route @...
Iván Mera's user avatar
1 vote
3 answers
3k views

Angular 17 route guard using Signal not working

I'm writing a route guard function using a signal from an auth service: export const canActivate: CanActivateFn = ()=> { console.log('guard called'); const authService = inject(HttpAuthService);...
Ben Ooms's user avatar
  • 213
0 votes
1 answer
457 views

How to wait for result from fetch (promise) in CanActivateFn guard to get user data from API in Angular project?

I need to implement a CanActivateFn guard to block non authenticated users in an Angular project. I tried different approaches and shaped this guard so far. import { inject } from '@angular/core'; ...
Galkin's user avatar
  • 843
0 votes
0 answers
30 views

On refreshing the child page I want the page to redirect to it parent's parent page in Angular

import { Parent1Component } from './parent1-shell.component'; const routes: Routes = [ { path: 'children1', component: children1, children: [ { path: 'subchildren1', ...
no_doubt's user avatar
0 votes
1 answer
513 views

Angular route guard executed before user authentication

I implemented a simple route guard that redirects to the login page if a user is not authenticated, where the check for login is of type Observable. The guard is working as expected, but if the user ...
Murmulodi's user avatar
  • 565
0 votes
1 answer
404 views

Using CanActivate and BreakpointObserver in Angular 15

The Angular 15 suggests using any JavaScript function as a CanActivate guard. I want to use BreakpointObserver inside this method. I have a BreakpointService which takes BreakpointObserver as a ...
wonderful world's user avatar
0 votes
1 answer
635 views

In lazy loading page is not loading till i click on the content of the page in angular 14

Hi Friends i had struct in this issue from past so many days below is my project structure the problem is that the page is not loading till i click on the website could anybody please help me out ? my ...
Ayub Baba's user avatar
0 votes
2 answers
1k views

rxjs observable unsubscribe in CanActivate Guard

I have one stupid question maybe: I'm implementing some routes guards that contains some other observable subscription, they are provided in root, so they should be singleton, no need to unsubscribe ...
G.D.'s user avatar
  • 65
2 votes
2 answers
1k views

Angular routing: Conditional route with library import

TL;DR How can I have a conditional route with conditional import of the corresponding Angular library during build time, depending on a feature flag in the environment file? Background I'm having a ...
dude's user avatar
  • 6,006
1 vote
2 answers
346 views

Angular Can Deactivate - Material Dropdown

I have an implementation of Angular RouteGuard CanDeactivate. It works for input fields but its not working for drop downs. I also want to display my own modal and I can't get it work correctly. This ...
JEuvin's user avatar
  • 991
0 votes
1 answer
254 views

How can I unsubscribe from this subscription?

I have a PolicyGuard with a method canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot). In canActivate I create an observable, and inside of this observable I subscribe to an ...
dgero95's user avatar
  • 64
-1 votes
2 answers
2k views

Angular RouteGuard "A function whose declared type is neither 'void' nor 'any' must return a value"

I have a route guard that checks if a user has access to a resource, before proceeding. After the subscription, I check if the user has access, and if not, redirect using parseUrl or return true. @...
Christian Phillips's user avatar
0 votes
1 answer
842 views

Angular Router Guard not resolving when the end result is true

The following code works correctly when the final if statement is true. Does not ever resolve the requested route when the final if statement is false. I've tried adding awaits and asyncs. I've tried ...
SDMitch's user avatar
  • 39

15 30 50 per page
1
2 3 4 5
7