在应用的路由模块中添加一个捕获所有路由的路由,将其放在其他路由之后,并将其指向404页面。
示例代码如下:
const routes: Routes = [ // other routes here { path: '**', component: NotFoundComponent} ];
其中,NotFoundComponent是自定义的404页面组件。使用双星号通配符来匹配所有未匹配到的路由,将其重定向到NotFoundComponent组件。
上一篇:Angular错误:无法解构属性'createHash',其值为'undefined'或'null'。
下一篇:Angular错误:无法匹配任何路由。URL片段:'null'。