1 import { Observable } from 'rxjs'
2 import { map } from 'rxjs/operators'
3 import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'
4 import { ResultList } from '@shared/models'
6 export abstract class AbstractLazyLoadResolver <T> implements Resolve<any> {
7 protected router: Router
9 resolve (route: ActivatedRouteSnapshot) {
10 const url = route.params.url
13 console.error('Could not find url param.', { params: route.params })
14 return this.router.navigateByUrl('/404')
17 return this.finder(url)
20 if (result.data.length !== 1) {
21 console.error('Cannot find result for this URL')
22 return this.router.navigateByUrl('/404')
25 const redirectUrl = this.buildUrl(result.data[0])
27 return this.router.navigateByUrl(redirectUrl)
32 protected abstract finder (url: string): Observable<ResultList<T>>
33 protected abstract buildUrl (e: T): string