How to Add Default Redirect in Angular


angular

To add default redirect you need to use the redirectTo and pathMatch=full properties in the route object. Set the redirectTo to a some path that exist in your routes and set pathMatch to the full:

const routes: Routes = [
  { path: '', redirectTo: '/chat', pathMatch: 'full' },
  { path: 'chat', component: ChatContainerComponent }
];

In this example, you will be redirected to the chat route when visiting the main page /. If you enter any other URL, you will be redirected to the main page only.

comments powered by Disqus