Angular2 redirect to custom error page

佐手、 提交于 2019-12-01 18:47:08

Main issue is that the routes var from the app-routing.module.ts has the entry to ** before the entry to error and the router will always go to **.

Moving the entry ** to the last place inside of routes will make the error entry reachable.

Also we found that after the updates the @Component({}) decorator of the CustomErrorComponent was removed.

Let's rollback that again and leave the CustomErrorComponent file with this code:

import { OnInit, Component } from '@angular/core';

@Component({
    selector: "customErrorComponent",
    templateUrl: './customerror.component.html'
})

export class CustomErrorComponent implements OnInit {
    constructor() { }

    ngOnInit() {
        console.log('customErrorComponent | ngOnInit...');
    }
}

Also we must add the CustomErrorComponent to the entryComponents of your main module.

Just add entryComponents: [CustomErrorComponent] to your main Module.

That did the job, future readers can check the chat thread of the question for more information.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!