It's important to note that in the latest version of @angular/router 3.0.0-rc.1
, you are unable to use the redirectTo
parameter if you are also utilizing the children
parameter.
In some scenarios, such as my own, there may be a need for this functionality. For instance, I want all requests to the parent router to automatically redirect to the first child route.
Here is an example of my router setup:
{
path: 'project/:id',
component: ProjectComponent,
children: [
{
path: 'properties',
component: ProjectPropertiesComponent
},
{
path: 'stats',
component: ProjectStatsComponent
}
]
}
I specifically desire any user accessing the project/:id
route to be redirected to the first child route (properties
) in my case.
Is there a way to achieve this?
If I try the following configuration:
{
path: 'project/:id',
component: ProjectComponent,
redirectTo: 'properties',
children: [
{
path: 'properties',
component: ProjectPropertiesComponent,
},
{
path: 'stats',
component: ProjectStatsComponent
}
]
}
I encounter the following error message:
EXCEPTION: Error: Invalid configuration of route 'project/:id': redirectTo and children cannot be used together