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 VideoLazyLoadResolver implements Resolve<any> {
9 private router: Router,
10 private searchService: SearchService
13 resolve (route: ActivatedRouteSnapshot) {
14 const url = route.params.url
17 console.error('Could not find url param.', { params: route.params })
18 return this.router.navigateByUrl('/404')
21 return this.searchService.searchVideos({ search: url })
24 if (result.data.length !== 1) {
25 console.error('Cannot find result for this URL')
26 return this.router.navigateByUrl('/404')
29 const video = result.data[0]
31 return this.router.navigateByUrl('/videos/watch/' + video.uuid)