import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , Resolve , Router , RouterStateSnapshot } from '@angular/router' ; import { Observable } from 'rxjs' ; import { Article , ArticlesService , UserService } from '../core' ; import { catchError , map } from 'rxjs/operators' ; @ Injectable ( ) export class EditableArticleResolver implements Resolve < Article > { constructor ( private articlesService , private router , private userService ) { } resolve ( route , state ) { return this . articlesService . get ( route . params [ 'slug' ] ) . pipe ( map ( article => { if ( this . userService . getCurrentUser ( ) . username === article . author . username ) { return article ; } else { this . router . navigateByUrl ( '/' ) ; } } ) , catchError ( ( err ) => this . router . navigateByUrl ( '/' ) ) ) ; } }