Questions tagged [angular-route-guards]

89 questions
1
vote
0 answers

Angular 6 static variable keeps getting reset to 'undefined'

I have a setup that is 'Services.Module' that knows about injectable services. It is loaded into 'app.module' under 'imports'. Everything works and the app functions fine with calls to endpoints on multiple services. However on an authorization…
djangojazz
  • 14,131
  • 10
  • 56
  • 94
1
vote
1 answer

CanActivate: Observable Boolean with Socket listener

I'm trying to grab a property from a socket from the server like this isVerified() { this.socket.emit('verify'); return new Observable(observer => { this.socket.on('isVerified', data => { observer.next(data) …
ErraticFox
  • 1,363
  • 1
  • 18
  • 30
1
vote
1 answer

Angular 6 Route Guard Shows White Page

I'm attempting to add a Route Guard that will send a JWT to a PHP API that will return true or false depending on if the user is authenticated. Through my testing, the Route Guard works until it actually calls the API. If the API returns false, the…
CaptainQuint
  • 332
  • 6
  • 22
1
vote
1 answer

angular route guard returns wrong value for observable

I'm trying to use a route guard to check if a user I logged in before accessing a route. for that i have a replaySubject contains true if a user is logged in. when i call my method for checking whether the user is logged in it's value is true, but…
1
vote
1 answer

Conditionally load modules in Angular 4

Is there any way to load module conditionally or prevent module access in some conditions? I just want to load modules and its subroutes only a specific condition satisfied. The possible solution I tried till now Lazy load modules with routing…
Mantu Nigam
  • 3,690
  • 7
  • 24
  • 41
1
vote
3 answers

Route guard: how to transform Observable into Observable

How can I transform an Observable into Observable. This is inside a route guard. Code: canActivate(next: ActivatedRouteSnapshot,state: RouterStateSnapshot): Observable { let obs = this.http …
gyozo kudor
  • 6,284
  • 10
  • 53
  • 80
0
votes
0 answers

Angular router window.open using ascii in url on first load, second load without closing works

Im trying to open a seperate window in angular. Initially it was done this way, which works: const url = `#/(fullscreen:order-line-details-history/${id})`; const windowName = 'All Order-line details-history'; const windowFeatures =…
0
votes
1 answer

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 dependency. export const isMobile = () => { return…
wonderful world
  • 10,969
  • 20
  • 97
  • 194
0
votes
0 answers

Invalid URL and routing to default URL

I am using angular for my website. When user enters wrong url, how to redirect to our home page. I have been using wildcard routing also. It works when user give wrong url like www.wename.com/test But it is not working when user gives like…
Raja Sekaran
  • 397
  • 4
  • 10
0
votes
1 answer

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 expecting is that the default that i had made in…
0
votes
2 answers

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 really. But what I'm doing is returning all the…
0
votes
1 answer

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 Observable that I retrieve from my AbilityService. The…
0
votes
1 answer

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 moving the code into a separate function that…
SDMitch
  • 39
  • 2
  • 6
0
votes
1 answer

Angular service variable updated value not reflected in component

I am facing issues while accessing the service variable values inside my angular component. Navbar component is setting user as logged in inside the service and routing guard is responsible for enabling children route, but routing guard is not able…
0
votes
1 answer

canActivate needs to wait for boolean of this.authService.isLoggedIn

I want my app to route to home : "" when the user logs in with their google email. Everything works except the canActivate routeGuard. this.authService.isLoggedIn returns false after I try to navigate to "" during the AuthLogin function. After…
artworkjpm
  • 1,255
  • 2
  • 19
  • 40