Angular2 router (@angular/router), how to set default route?

后端 未结 10 1995
广开言路
广开言路 2020-12-02 15:07

How can I set a default route in my @Routes route metadata collection? If you use the angular2 router from @angular/router-deprecated you define the routes in @routeConfig

10条回答
  •  攒了一身酷
    2020-12-02 15:35

    I faced same issue apply all possible solution but finally this solve my problem

    export class AppRoutingModule {
    constructor(private router: Router) {
        this.router.errorHandler = (error: any) => {
            this.router.navigate(['404']); // or redirect to default route
        }
      }
    }
    

    Hope this will help you.

提交回复
热议问题