New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigating to error page from error handler when error thrown in ngOnInit #16246

Open
jonmikelm opened this Issue Nov 6, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@jonmikelm

jonmikelm commented Nov 6, 2018

Bug Report

Ionic Info
Run ionic info from a terminal/cmd prompt and paste the output below.

Ionic:

   ionic (Ionic CLI)             : 4.2.1 (D:\Users\******\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.0.0-beta.15
   @angular-devkit/build-angular : 0.7.5
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 6.2.5
   @ionic/angular-toolkit        : not installed

System:

   NodeJS : v10.11.0 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 7

Describe the Bug
When an error is thrown in the ngOnInit method of a page component, and a custom error handler is defined to redirect to an error page, both the page that generated the error and the error page are rendered inside the ion-router-outlet.

Steps to Reproduce
Steps to reproduce the behavior:

  1. Navigate to a page, e.g:
this.navCtrlr.navigateRoot('public/page1');
  1. Throw an error in ngOnInit
ngOnInit() {
  throw 'error';
}
  1. Handle the error in a custom angular error handler
public handleError(error: any): void {
  const navCtrlr = this.injector.get(NavController);
  ngZone.run(() => {
    navCtrlr.navigateRoot('public/errorPage');
  });
}
  1. Inspect DOM and verify that ion-router-outlet contains both components, with page1 on top.
<ion-router-outlet>
  <page-1>...</page-1>
  <error-page>...</error-page>
</ion-router-outlet>

Related Code

Expected Behavior
The navigation to page1 should be canceled and the component removed from outlet. The error page should be shown.

Additional Context
I've tried with and without using ngZone while navigating in the custom error handler but the result is the same.
This old angular issue is closed but problems can be related:
angular/angular#19218

@ionitron-bot ionitron-bot bot added the triage label Nov 6, 2018

@selipso

This comment has been minimized.

selipso commented Nov 6, 2018

Have you tried using a route guard? It seems like that would be a more appropriate method for what you are trying to achieve.

https://codeburst.io/using-angular-route-guard-for-securing-routes-eabf5b86b4d1

@almothafar

This comment has been minimized.

almothafar commented Nov 7, 2018

I feel it could be a side effect for the router issues that appeared with beta 15, do you have the same issue in beta 13? look at #16244

@jonmikelm

This comment has been minimized.

jonmikelm commented Nov 7, 2018

I've just tested it with beta 13 and the result is the same.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment