Angular 2 redirect in Interceptor Error

Discussão em 'Angular' iniciado por User, Janeiro 1, 2025.

  1. User

    User Guest

    I have written this intercept method:

    intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
    return next.handle(req).do(event => {
    console.log('EVENT:', event);
    }, (err: HttpErrorResponse) => {
    const message = err.error.message;
    if (message == 'You need to activate your account!') {
    // TODO: Redirect to '/auth/not-activated'
    }
    });
    }


    If I receive from server specific error message, I need to redirect user to address /auth/not activated

    How can I achieve that?

    I have already tried

    this.router.navigateByUrl(url);


    but this is not working.

    Continue reading...

Compartilhe esta Página