Created
June 24, 2022 07:47
-
-
Save NetanelBasal/7f3b998406961e3b28702549f29c80dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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