I have a redirect defined in app-routing.module and have no ideas why is it not working. If I use a default path for ""(code that is currently commented out) instead of a redirect then it works fine.
@NgModule({
imports: [
RouterModule.forRoot([
{
path: "actions",
component: ActionsComponent
},
//{
// path: "",
// component: LoginComponent
//}
{
path: "",
redirectTo: "/login",
pathMatch: "full"
}
])
],
exports: [
RouterModule
]
})
Any ideas? Code is in http://plnkr.co/edit/y970zDKDZRIZ5LQA8v1T?p=preview
In your reproduction you don't have really /login path because the second router-outlet don't know which child of the login route should be process.
In the answer of @Ha Hoang if you comment below line :
{ path: "", redirectTo: "login", pathMatch: "full" }
your app still work ! because (path: "") override in login-routing.module on line :
{ path: '', component: LoginComponent }
but I think the way of @Ha Hoan is not logical because the path="" should not be load LoginComponent it should redirect to /login url and then path="login" should load LoginComponent my suggestion is :
In app-routing.module: use /login/loginDetails instead of /login
{
path: "",
redirectTo: "/login/loginDetails",
pathMatch: "full"
}
then your plunker work correct and the structure of the routing is better. http://plnkr.co/edit/YENJ4Wm26qMty5mOR1dA?p=preview
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With