94
questions
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] }...
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 ...
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
@...
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);...
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';
...
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',
...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
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 ...
-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.
@...
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 ...