import { Injectable , } from '@angular/core' ; import { ActivatedRouteSnapshot , Resolve , Router , RouterStateSnapshot } from '@angular/router' ; import { Observable } from 'rxjs' ; import { Profile , ProfilesService } from '../core' ; import { catchError } from 'rxjs/operators' ; @ Injectable ( ) export class ProfileResolver implements Resolve < Profile > { constructor ( private profilesService , private router ) { } resolve ( route , state ) { return this . profilesService . get ( route . params [ 'username' ] ) . pipe ( catchError ( ( err ) => this . router . navigateByUrl ( '/' ) ) ) ; } }