import { Injectable } from '@angular/core' ; import { ActivatedRouteSnapshot , Resolve , Router } from '@angular/router' ; import { of , Observable } from 'rxjs' ; import { catchError , take } from 'rxjs/operators' ; import { RepositoryService } from '@core/services/index.service' ; import { RepositoryModel } from '@shared/models/index.model' ; @ Injectable ( { providedIn : 'root' , } ) export class RepositoryResolver implements Resolve < RepositoryModel > { constructor ( private respositoryService , private router ) { } resolve ( route ) { return this . respositoryService . findOneById ( route . params . repoUid ) . pipe ( take ( 1 ) , catchError ( ( ) => { this . router . navigate ( [ '/projects' , route . params . projectUid ] ) ; return of ( new RepositoryModel ( { uid : '-' } ) ) ; } ) ) ; } }