Questions tagged [canactivate]
145 questions
4
votes
2 answers
Angular 2 - CanActivate Observable get value after Subscribe
I have a "CanActivate" checking on my web service if the user is logged in.
The "CanActivate" return Observable. The only worry is that I would need to recover the value of this boolean in order to be able to adapt my view if the user is connected…

Jordan R.
- 59
- 2
- 6
3
votes
1 answer
The guard does not work the second time in angular 11
I am configuring a guard for my angular app and it happens that when I run the application and log in the first time it works fine, but I configure an error interceptor where I have a condition that when the user receives a 401 error from the api it…

Deybi Tabora Paz
- 171
- 3
- 11
3
votes
2 answers
canActivate not working when url is typed
Basically everything works correctly until for some reason when the url is typed the variable this.estado within the method canActivate happens to be undefined.
I think that this because the constructor does not get the observable at the correct…

Kelevra
- 35
- 5
3
votes
1 answer
How to apply routing guards to feature module routing modules?
So, I'm building an Angular 4 app that I want all routes to be protected (except for the login route of course). I'm trying to use feature modules and feature module routing. So, imagine something like this:
import { NgModule } from…

Iraklis Alexopoulos
- 909
- 2
- 14
- 27
3
votes
3 answers
Angular2 : How to redirect to the login page when observable subscription fails?
In the file auth-guard-service.ts, why is the call this.router.navigateByUrl('/login') not working, while the alert message is printed ? The other call in the other file (auth.service.ts) works correctly.
auth-guard-service.ts
import { Injectable } …

dng
- 411
- 1
- 5
- 18
3
votes
1 answer
Angular2: AuthGuard not working when using browser navigation buttons
I've got a simple AuthGuard configured, that works perfectly fine when navigating "normally" through the application (see code below).
Now imagine following:
User navigates to /content/secured-content, which requires authentication => he is being…

Naduweisstschon
- 78
- 5
2
votes
1 answer
How to access the current Url Segment that is being tested in the Guard
I have a generic CanActivate guard and want to alter the matrix params of the corresponding path segment (the one being tested).
With given route config:
{
path: 'parent',
canActivate: [ensureSortMatrixParamsGuard],
children: [
{ path:…

mumenthalers
- 51
- 7
2
votes
1 answer
angular 9 why canActivateChild start befor canActivate completed?
in my program I have a func in canActivateChild that need to occur
after canActivate finished , but the child component loads befor canActivate of the parent finish,why?
my routing-module:
const routes: Routes = [
{
path: '',
component:…

Hinda
- 21
- 2
2
votes
2 answers
Delay canActivate call when page refreshes in order to wait for the data to load
When I reload my page, it always goes to blank page instead of the same page. The reason behind this is canActivate method which is cheking for user's permission gets invoked as soon as user refreshes the page and it is not able to get user data…

Radiant
- 360
- 3
- 26
2
votes
1 answer
Problem of ending return statement on canActivate
I have a problem when I use CanActivate method: error ts2366 "Function lacks ending return statement and return type does not include undefined" appears.
Following my code:
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot,…

thomas rocheteau
- 53
- 5
2
votes
1 answer
angular - How to create a canActivate guard to only allow redirects from another component?
I have a component that I wish to allow it's access only in case of a redirect from another component.
So if I put the url in the browser it wouldn't allow me to access it but, if I redirect to it from another specific component like this it will be…

wazzup
- 39
- 7
2
votes
1 answer
Angular routing same path different guard
I want to use the same path ticket because I want to redirect when save something (Use same component to Update Ticket ).
But there is a problem with canActivate. What is the best way to fix it?
const router: Routes = [
{
path: '',
…

Puthxii
- 47
- 9
2
votes
1 answer
Lazy Loaded Module with CanActivate guard for checking Roles of logged in user
I have a lazy loaded module with canActivate guard and after the lazily loaded module is loaded, somehow the page is made unauthenticated (say by logging in as a different role in different tab of same browser), so when we try to access previous…

khush
- 2,702
- 2
- 16
- 35
2
votes
2 answers
Angular - Resolving Observable data before canActivate
I’m working on a web application using Angular and i came across a problem.
There is an Authentication service that logs in a user. I’m sending a request to
the server with the credentials and waiting for a response. The problem is that I
try to…

NVelichkovski
- 31
- 1
- 7
2
votes
1 answer
Angular Route Guard CanActivate stops routing
I am trying to check weather the user has already selected a company to login. If they select then they see those company employees. Otherwise, we will redirect to login page.
I have used Angular Route Guard to do this. But its not continuing the…

Developer
- 487
- 9
- 28