Route doesn't load when resolver enabled in Angular 4

Viewed 398

everyone! I've got a weird problem with the resolver. When I comment it out from my route - everything's working fine. But when I add it - it simply blocks everything. My route config is like this:

{
  path: '',
  resolve: {results: HotelsSearchResolver},
  component: EntrySearchComponent,
  runGuardsAndResolvers: 'paramsOrQueryParamsChange'
}

And my resolver is here:

constructor(private searchService: SearchService,
          private store: Store<ApplicationState>) { }

resolve(route: ActivatedRouteSnapshot, state: RouterStateSnapshot):
  Observable<SearchResultModel> {

  console.log('resolver fired!');
  const key = route.queryParams['key'];
  console.log(key);

  return this.store
    .select(appState => appState.searchState)
    .do(console.log)
    .map(searchState => searchState.results[key])
    .do(console.log)
}

I try to get the data in EntrySearchComponent like this:

constructor(private route: ActivatedRoute) { 
  route.data.pluck('results').subscribe(console.log)
}

I see all the console.logs except for the one in EntrySearchComponent. And of course, I added the resolver to my providers in AppModule. Any suggestions, what might be the problem?

Thanks for your help!

0 Answers
Related