Skip to content

Instantly share code, notes, and snippets.

@NetanelBasal
Created June 24, 2022 07:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NetanelBasal/7f3b998406961e3b28702549f29c80dd to your computer and use it in GitHub Desktop.
Save NetanelBasal/7f3b998406961e3b28702549f29c80dd to your computer and use it in GitHub Desktop.
@Injectable({ providedIn: 'root' })
export class MyGuard implements CanActivate {
constructor(private router: Router, private route: ActivatedRoute) { }
canActivate(route: ActivatedRouteSnapshot) {
if(checkData(route)) {
this.router.navigate(['../sibling'], { relativeTo: this.route });
return false;
}
return true;
}
}
const routes: Routes = [{
path: 'parent',
component: ParentComponent,
children: [
{
path: 'child',
component: ChildComponent,
canActivate: [MyGuard]
},
{
path: 'sibling',
component: SiblingComponent
}
]
}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment