I have a component to which navigate like this
this.router.navigate(['results'], { state });
and once there i grab the data in the contructor
constructor(private router: Router) {
const { state } = this.router.getCurrentNavigation().extras;
}
i want to place a guard to check for the existense of this data, otherwise navigate elsewhere
@Injectable()
export default class RouteHasDataGuard implements CanActivate {
canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return !!state.root.data;
}
}
but this isnt working. can you help me with this?
return !!state.root.data
to figure out when it gets hit and if you're looking in the right object for yourstate
data. – Anesthesia