Skip to content

Instantly share code, notes, and snippets.

@nathan-lapinski
Created November 23, 2018 15:42
Show Gist options
  • Save nathan-lapinski/b35370a7ecf5273687e3bebd74e160f1 to your computer and use it in GitHub Desktop.
Save nathan-lapinski/b35370a7ecf5273687e3bebd74e160f1 to your computer and use it in GitHub Desktop.
example guard which returns a UrlTree
import { Injectable } from '@angular/core';
import { CanActivate,
ActivatedRouteSnapshot,
RouterStateSnapshot,
Router,
UrlTree } from '@angular/router';
@Injectable()
export class CanActivateRouteGuard implements CanActivate {
constructor(private router: Router) {}
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean | UrlTree {
const url = 'target';
const tree: UrlTree = this.router.parseUrl(url);
return tree;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment