When the application start, it navigates to the empty route by default. We can configure the router to redirect to a named route by default. So, a redirect route translates the initial relative URL (”) to the desired default path.
For example, if you want to redirect to Login page or registration page by default when the application start. Then you need to configure the redirectTo
Syntax
Example
Create a Component
Continuation of Previous Example,
https://dotnetbyudayrajakonda.blogspot.com/2023/10/routing-example-2.html
Add the below code in appModule.ts
The empty path in the first route represents the default path for the application. This default route redirects to the route for the /Login URL and therefore will display the Login Component
A redirect route requires a pathMatch property to tell the router how to match a URL to the path of a route. The router throws an error if you don’t. For the special case of an empty URL we also need to add the pathMatch: ‘full’ property so angular knows it should be matching exactly the empty string and not partially the empty string.
Instead of showing the default page when the URL is empty, we want to redirect to the Login page. This is where Redirecting Routes comes into picture in Angular Application.
Now, Run
No comments:
Post a Comment
Thank you for visiting my blog