1 import { map } from 'rxjs/operators'
2 import { Injectable } from '@angular/core'
3 import { ActivatedRouteSnapshot, Resolve, Router } from '@angular/router'
4 import { SearchService } from '@app/shared/shared-search'
7 export class ChannelLazyLoadResolver implements Resolve<any> {
9 private router: Router,
10 private searchService: SearchService
13 resolve (route: ActivatedRouteSnapshot) {
14 const url = route.params.url
15 const externalRedirect = route.params.externalRedirect
16 const fromPath = route.params.fromPath
19 console.error('Could not find url param.', { params: route.params })
20 return this.router.navigateByUrl('/404')
23 if (externalRedirect === 'true') {
25 this.router.navigateByUrl(fromPath)
29 return this.searchService.searchVideoChannels({ search: url })
32 if (result.data.length !== 1) {
33 console.error('Cannot find result for this URL')
34 return this.router.navigateByUrl('/404')
37 const channel = result.data[0]
39 return this.router.navigateByUrl('/video-channels/' + channel.nameWithHost)