[英]Angular children routes in Lazy Loaded module don't completely work
I am using Angular 2.3.1 我正在使用Angular 2.3.1
I having trouble navigating to children routes in a lazy loaded module. 我无法在延迟加载的模块中导航至子级路由。 What is very odd to me is that 2 of 3 children routes are working perfect.
对我来说,很奇怪的是3条儿童路线中有2条路线表现理想。 But when I tried to add a 3rd route, it's that particular route that doesn't seem work.
但是,当我尝试添加第三条路线时,该特定路线似乎无效。
Because some routes are working, you would think it's a problem with the component that's associated with the ill fated route...but I don't believe this is the case...The component is just bare bones class & template. 因为某些路由有效,所以您会认为与病态路由相关的组件存在问题...但是我不认为这种情况...该组件只是裸露的类和模板。 There's nothing in it:
里面什么都没有:
Here is my Root App Routing 这是我的根应用程序路由
const routes: Routes = [
{path:'', component: HomePageComponent},
{
path: 'facilities',
loadChildren: './search-page/search-page.module#SearchPageModule'
},
]
@NgModule({
imports: [RouterModule.forRoot(routes, {preloadingStrategy: PreloadAllModules})],
exports: [RouterModule],
providers: []
})
Here is my module routing , where I'm creating children routes. 这是我的模块路由 ,我将在其中创建子路由。
const searchPageRoutes : Routes = [
{
path: '',
component: SearchPageComponent,
children: [
{
path:'search', // ROUTE WORKS
component: SearchResultsComponent,
canActivate: [FacilitiesGuard]
},
{
path: ':id', // ROUTE WORKS
component: FacilityDetailComponent,
resolve: {facility: FacilityDataResolver }
},
{
path: 'saved', // ROUTE NOT WORKING
component: FacilitiesListComponent
}
]
}
];
@NgModule({
imports: [
RouterModule.forChild(searchPageRoutes)
],
exports:[
RouterModule
]
})
ERROR The error I'm getting is the same error that occurs if I remove the route all together...as if the route is not even being defined. ERROR我得到的错误是,如果我删除了所有的路线是一起发生同样的错误......仿佛路线甚至没有被定义。 Angular tries to make a backend API call with the route:
Angular尝试使用该路由进行后端API调用:
http://localhost:8080/api/facilities/saved (500) Internal server Error
This error occurs because this route doesn't exist in the API. 发生此错误是因为该路由在API中不存在。
What am I doing wrong or why is the 'saved' route not being found by angular? 我在做什么错?为什么没有通过角度找到“保存的”路线?
Answer based on comment conversation: 根据评论对话的答案:
The issue here is the order of the routes in the configuration. 此处的问题是配置中路由的顺序。
This: 这个:
{
path: ':id', // ROUTE WORKS
component: FacilityDetailComponent,
resolve: {facility: FacilityDataResolver }
},
{
path: 'saved', // ROUTE NOT WORKING
component: FacilitiesListComponent
}
Needs to be this: 需要这样的:
{
path: 'saved', // ROUTE WORKING NOW!
component: FacilitiesListComponent
},
{
path: ':id', // ROUTE STILL WORKS
component: FacilityDetailComponent,
resolve: {facility: FacilityDataResolver }
}
Essentially, the router thinks that anything trying to go to the saved
route was stopped at the :id
route, because the router is thinking that the term "saved" was just another parameter be passed to it. 本质上,路由器认为尝试进入已
saved
路由的所有操作都在:id
路由处停止,因为路由器认为“保存”一词只是传递给它的另一个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.