Angular2 redirect to custom error page

后端 未结 1 838
情书的邮戳
情书的邮戳 2021-01-19 17:10

I\'ve implemented my custom error handler, and in that I want to re-direct to my custom error page that just says \"sorry, an error occurred......\".

I declared a ro

相关标签:
1条回答
  • 2021-01-19 17:34

    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.

    0 讨论(0)
提交回复
热议问题