2017-04-02 8 views
0

私のアプリケーションにはデフォルトのエラーページがあります。 デフォルトのエラーページ:angular2

import { ErrorHandler, Injectable, Injector } from '@angular/core'; 
import { Router } from '@angular/router'; 

@Injectable() 
export class GlobalErrorHandler implements ErrorHandler { 
    router: Router; 

    constructor(private injector: Injector) { 
    this.router = this.injector.get(Router); 
    } 

    handleError(error) { 
    this.router.navigate(['error']); 
    throw error; 
    } 
} 

と同様のエラーページの構成要素とルートを作成します:それを達成するために、私は、エラーハンドラを実装

export const routes: Routes = [ 
    { path: '', component: RecipeListComponent }, 
    ... 
    { path: 'error', component: ErrorPageComponent } 
]; 

が、この行を、エラーHadler博士では動作しません...誰かが持っています理由についてのいくつかのアイデア?

this.router.navigate(['error']); 

エラーが発生しましたが、エラーページにルーティングできません。子ルートがpathMatch: 'full'

{ path: '', component: RecipeListComponent, pathMatch: 'full' }, 

必要がある空のパス''

答えて

1

ルートとすることなく、また有力/はナビゲーションがすべての場合で動作が保証

this.router.navigate(['/error']); 
関連する問題