I have a resolver like this:
export class TaskResolver implements Resolve<Documents> {
constructor(private taskService: TaskService) { }
resolve(route: ActivatedRouteSnapshot): Observable<Documents> {
const taskId = route.params.taskId;
return this.taskService.DocumentsTask(taskId);
}
}
And inside my component I have:
this.route.data.subscribe((data: { documents: Documents }) => {
if (data.documents) {
this.documents = data.documents;
} else {
this.router.navigate([`/error/404`]);
}
});
I need to move the this.router.navigate([/error/404
]); inside resolver, that way the resolver will check if the data is empty and redirect to error, and not the component. Or maybe move to auth guard that looks like this
canActivate(route: ActivatedRouteSnapshot): boolean {
const taskId = route.params.taskId;
if (taskId) {
return true;
}
}
DocumentsTask(taskId) returns Observable