Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

If user input a not-existing link, I want the page redirect to Home page.

How can I do it? Thanks

@RouteConfig([
    {path: '/home', name: 'Home', component: HomeComponent},
    {path: '/about', name: 'About', component: AboutComponent},
    {path: '/???', name: 'not-found', redirectTo: ['Home']}
])
like image 349
Hongbo Miao Avatar asked Feb 08 '23 17:02

Hongbo Miao


1 Answers

This will redirect all unregistered routes to Home

{ path: "/**", redirectTo: ["Home"] }
like image 187
Daniel Rasmuson Avatar answered Feb 11 '23 16:02

Daniel Rasmuson