1

I have an Angular Universal Website and I've written the following resolver:

import { Inject, Injectable, OnDestroy } from '@angular/core';
import { Resolve, ActivatedRouteSnapshot, RouterStateSnapshot } from '@angular/router';
import { Subscription, Observable, map, tap, forkJoin, catchError, of, pipe } from 'rxjs';
import { ActivatedRoute, Router } from '@angular/router';
import { REQUEST } from '@nguniversal/express-engine/tokens';
import { Request } from 'express';

@Injectable()
export class SessionResolver implements Resolve<boolean>, OnDestroy {
  constructor(@Inject(REQUEST) private request: Request) {

  }

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

    console.log(this.request.headers['accept-language']);
    return of(false);
    
    }

}

But the moment I do Inject(REQUEST) private request: Request

My page briefly flashes up and then goes white. No other error message is delivered.

How come I can't use this line and what would the alternative be?

Andrew Howard
  • 2,818
  • 5
  • 33
  • 59
  • If you use resolvers and the router cannot resolve those values when routing to that particular route, routing will simple cancel. Hence the white page. You can enable tracing to see more details on what exactly is happening during routing. See [the documentation here](https://angular.io/api/router/ExtraOptions#extraoptions) and an [example here](https://stackoverflow.com/a/45669041/1697459) on how and where to enable tracing. – Wilt Apr 12 '23 at 15:33
  • Also a question, does it route correctly if you remove the dependency from the constructor? – Wilt Apr 12 '23 at 15:43
  • Hi @Wilt yes it does route correctly if I remove the dependency – Andrew Howard Apr 12 '23 at 15:48
  • Is `REQUEST` properly provided somewhere (through a module provider)? – Wilt Apr 12 '23 at 15:50
  • REQUEST is a built-in thing to Angular Universal. It links to it all fine. – Andrew Howard Apr 12 '23 at 15:52

0 Answers0