To find more information :
Questions tagged [angular-router-guards]
289 questions
0
votes
2 answers
Fetch async data before component render using a resolver
I would like to fetch an async data from a server before starting to render a component. I've attempted to use a route resolver, but I cant see how it can help.
I can access the resolver data in the component via ActivatedRoute using:
ngOnInit()…

amit
- 2,171
- 4
- 31
- 50
0
votes
1 answer
Angular component not rendered after successful login
Menu Component (should be only visible after a successful login)
import { Component, OnInit } from '@angular/core';
import { Router } from '@angular/router';
import { AuthService } from '../../services/auth.service';
@Component({
selector:…

woodykiddy
- 6,074
- 16
- 59
- 100
0
votes
2 answers
How to redirect to Home page on refresh using Angular 2?
I am using Angular CLI to build app. I have configured routes as shown below:
const routes: Routes = [
{path: 'Home', component: HomeComponent},
{path: 'About', component: AboutUsComponent},
{ path: '**', pathMatch: 'full', redirectTo: 'Home'…

Tavish Aggarwal
- 1,020
- 3
- 22
- 51
0
votes
1 answer
Clear localStorage on every refresh in angular 2
I am storing a token in localStorage after authentication, but i need to delete it and redirect to some router each time i do a refresh.
I have no ideea how to do it in angular. I am using a very hacky way using plain…
user5349610
0
votes
1 answer
Angular 4 CanActivateChild doesn't work
I'm trying to restrict access to my route system using CanActivateChild, however when I try to prevent user's navigation to a set of child states, the RouteGuard doesn't work, only on CanActivate. This is my routing module:
export const routes = [
…

celsomtrindade
- 4,501
- 18
- 61
- 116
0
votes
1 answer
How show only links to modules that I can active in Angular?
I use router and guards with CanActivate. It works fine, but I need show only in my menu the "activable" links.
Has router any option as "isActivable"?
Example:
-
MiguelAngel_LV
- 1,200
- 5
- 16
0
votes
1 answer
Using a Callback Function in AuthGuard
if I have the following implementation of CanActivate in an AuthGuard:
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
let token = localStorage.getItem('token');
if (token) {
this.authService.userInfo(token,…

Sammy
- 3,395
- 7
- 49
- 95
0
votes
1 answer
How to resolve local data wrapped in an observable then replace data with remote in Angular+
What I'm doing:
I have an angular resolve guard on my route /work/:slug. I would like to instantly resolve that guard with an Observable of local data, while remote data is being fetched over the network. After the network request is successful,…

Armeen Moon
- 18,061
- 35
- 120
- 233
-1
votes
1 answer
TS7030: Not all code paths return a value. Guard, canActivate method Angular13
I am trying to use guards for an unlogged user, but ts always returns an error
TS7030: Not all code paths return a value.
My auth.guard.ts file:
import { ActivatedRouteSnapshot, CanActivate, Router, RouterStateSnapshot, UrlTree} from…

Gaiaz Apkaev
- 3
- 1
-1
votes
1 answer
Cannot find name 'canActivate'
Guys i'm trying to make a auth guard to guard routes that someone who isnt authenticated cannot access. In my AuthService i imported Can Activate like this:
import { CanActivate, ActivatedRouteSnapshot } from '@angular/router';
I also used the…

Paula Bremenkamp
- 37
- 8
-1
votes
1 answer
How to redirect to the route in Angular if URL corresponds to the special pattern?
I have the URLs:
/example.com/client/page-1?param=data
/example.com/client/page-2
/example.com/client/page-3?newparam=data
I want to redirect user to the following pages while they open the…

Eugene
- 9
- 5
-1
votes
1 answer
How to pass data from guard of a child component to parent component?
I have a parent component that has a bun of tabs with links. Each tab has a link that will navigate to the child component. The parent tab has a header data such as client name, dob, gender, ...
The parent component .HTML looks like the following:
…

Ray
- 781
- 2
- 17
- 42
-1
votes
3 answers
Angular execute service function before load any route
I have a service (LocationService) that contains the user's country based on his gps coordinates and the functions to get the gps coordinates and do the reverse geocoding. My idea is to use the service to store the country and if the value is null…

jcobo1
- 1,065
- 1
- 18
- 34
-1
votes
1 answer
Minimal mock for unit testing angular Router and CanActivate guard
import {Router, ActivatedRouteSnapshot, RouterStateSnapshot, UrlTree} from '@angular/router';
@Injectable({provideIn: 'root'})
export class FooGuard implements CanActivate {
constructor (private readonly router: Router) {}
canActivate (next:…

c69
- 19,951
- 7
- 52
- 82
-1
votes
1 answer
Wait for auth request to complete before checking if user is logged in with route guards
EDITED BELOW
I don't want to make a call to determine if a user is authenticated every time the route changes, but I do want to check that if they refresh the page on an authenticated route, they can access it. I can't seem to make this work.
I have…

Jer_TX
- 465
- 4
- 20