简体   繁体   English

延迟加载模块中的角子级路由无法完全正常工作

[英]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.

相关问题 延迟加载模块路由的子节点不起作用 - Children of Lazy Loaded Modules routes don't work Angular 7 嵌套延迟加载子路由 - Angular 7 Nested Lazy Loaded Children Routes 具有子路由的延迟加载模块中的角度路由 - angular routing in lazy loaded module with child routes Angular 6-延迟加载模块的子路径未加载 - Angular 6 - Children paths of lazy loaded module are not loading 在子延迟加载模块中使用参数进行角路由? 无法匹配每次抛出的任何路线 - Angular routing with parameters in a child, lazy-loaded module? Can't match any routes thrown every time 尝试使用 forRoot() 为延迟加载的组件延迟加载与 Angular Material 相关的自定义模块不起作用 - Trying to lazy load Angular Material related custom module for lazy loaded components using forRoot() doesn't work 延迟加载模块的子路径不在角元素中工作 - Lazy Loaded module's children route not working in angular elements Angular 6 如何在延迟加载的模块中初始化辅助路由 - Angular 6 How to initialize auxiliary routes within a lazy loaded module Angular:如何在延迟加载的路由中使用外部模块 - Angular: How to use external module in lazy loaded routes Angular延迟加载模块无法导航到子路由 - Angular lazy loaded module failed to navigate to child routes
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM