-1

I want to redirect at Home page if user type any URL which is not exist in system

4

2 回答 2

2

app.module.ts中,将以下行添加到imports列表中的其他模块之后。如果它是在其他路由之前添加的,它将重定向到这些路由的主页。

RouterModule.forChild([{ path: '**',   redirectTo: '/' }])

您还需要导入RouterModule

import { RouterModule } from '@angular/router';
于 2018-10-07T18:36:41.550 回答
0

You can use ** rule at the end of your navbar.routes to redirect to Home page. Below is the example:

{ path: '**', component: HomeComponent}
于 2018-10-07T14:45:38.933 回答