Angular2 router (@angular/router), how to set default route?

后端 未结 10 2010
广开言路
广开言路 2020-12-02 15:07

How can I set a default route in my @Routes route metadata collection? If you use the angular2 router from @angular/router-deprecated you define the routes in @routeConfig

10条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-02 15:53

    I just faced the same issue, I managed to make it work on my machine, however the change I did is not the same way it is mentioned in the documentation so it could be an issue of angular version routing module, mine is Angular 7

    It only worked when I changed the lazy module main route entry path with same path as configured at the app-routes.ts

    routes = [{path:'', redirectTo: '\home\default', pathMatch: 'full'},
               {path: '', 
               children: [{
                 path:'home',
                 loadChildren :'lazy module path'      
               }]
    
             }];
    
     routes configured at HomeModule
     const routes = [{path: 'home', redirectTo: 'default', pathMatch: 'full'},
                 {path: 'default', component: MyPageComponent},
                ]
    
     instead of 
     const routes = [{path: '', redirectTo: 'default', pathMatch: 'full'},
                       {path: 'default', component: MyPageComponent},
                    ]
    

提交回复
热议问题