I\'ve defined some routes
in my main.ts
file:
const routes: RouterConfig = [
{ path: \'\', component: HomeComponent },
{ path:
I made some researches to see if it's possible to "negate" a guard but seems like you have to make another guard which is the opposite of your guard. Like :
import { Injectable } from '@angular/core';
import { CanActivate } from '@angular/router';
import { AuthService } from './your-auth.service';
@Injectable()
export class PreventLoggedInAccess implements CanActivate {
constructor(private authService: AuthService) {}
canActivate() {
return !this.authService.isLoggedIn();
}
}
Add it in your bootstrap function as well and you are all set. You just have to do in your routes :
{ path: 'login', component: LoginComponent, canActivate: [PreventLoggedInAccess] },