How to redirect not-existing link to Home page in Angular 2?

99封情书 提交于 2019-12-05 13:57:01

This will redirect all unregistered routes to Home

{ path: "/**", redirectTo: ["Home"] }

In Routing of the version v4 name property no more exist. route define without name property. so you should use path instead of name redirectTo: '/redirectPath' and no leading slash for path so use path: '404' instead of path: '/404'

like:

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