import { Injectable } from '@angular/core';
-import { CanActivate, CanActivateChild, Router } from '@angular/router';
+import {
+ ActivatedRouteSnapshot,
+ CanActivate,
+ CanActivateChild,
+ Router,
+ RouterStateSnapshot
+} from '@angular/router';
import { AuthStorageService } from './auth-storage.service';
export class AuthGuardService implements CanActivate, CanActivateChild {
constructor(private router: Router, private authStorageService: AuthStorageService) {}
- canActivate() {
+ canActivate(_route: ActivatedRouteSnapshot, state: RouterStateSnapshot) {
if (this.authStorageService.isLoggedIn()) {
return true;
}
- this.router.navigate(['/login']);
+ this.router.navigate(['/login'], { queryParams: { returnUrl: state.url } });
return false;
}
- canActivateChild(): boolean {
- return this.canActivate();
+ canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
+ return this.canActivate(childRoute, state);
}
}