2017-04-02 6 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; 
    } 
} 

및 오류 페이지 구성 요소 및 경로뿐만 아니라 생성 : hadler이 작동하지 않는 오류에

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

하지만이 줄을 ... 누군가가 그것을 달성하기 위해, 나는 오류 처리기를 구현 이유에 대한 몇 가지 생각? 내 말은

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

, 나는 오류가 발생하고있어하지만 난 내 오류 페이지로 라우팅 할 수 아니에요! 아이 노선이 pathMatch: 'full'

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

필요가 빈 경로 ''

답변

1

경로와 않고 또한 선도적 인 / 탐색이 모든 경우에 작동 보장

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