Angular 12:升级后,路由器输出并未渲染组件

发布于 2025-02-11 13:59:21 字数 877 浏览 1 评论 0 原文

我已经从旧导入方式中更改了路由器导入的导入,

loadChildren: './lazy/lazy.module#LazyModule

我使用了动态导入来加载路由器模块。

loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)

现在,我不是在渲染组件,而是渲染组件,同时标头和页脚,组件加载正常,因为它没有从路由器输出中加载。

app.component.html

<header-component>.  //rendering fine
<router-outlet></router-outlet>. // I am seeing it gets routed in the address bar, but the component is not getting rendering.
<footer-component> //rendering fine 

我在上述问题的控制台或VSCODE上没有任何错误。 当组件空白时,我该如何调试此问题,尽管它的路由正确,但我也将在“网络”选项卡中获得此组件的API响应,因此API响应不会在屏幕上以HTML呈现。

当我从Angular 11升级到12版时,这个问题发生在我身上。

我的详细代码结构与此文档

I have changed my router import from old way of importing

loadChildren: './lazy/lazy.module#LazyModule

I have used dynamic import to load the router module.

loadChildren: () => import('./lazy/lazy.module').then(m => m.LazyModule)

Now, my is not rendering the components but at the same time header and footer, component are loading fine since it is not loaded from the router-outlet.

app.component.html

<header-component>.  //rendering fine
<router-outlet></router-outlet>. // I am seeing it gets routed in the address bar, but the component is not getting rendering.
<footer-component> //rendering fine 

I don't get any error on the console or vscode for the above issue.
How do I debug this issue while the components are blank though it is routed correctly also I am getting an API response for this component in the network tab the API response is not get rendered on the screen as HTML.

This issue happened to me while I am upgrading from Angular 11 to the 12 version.

My detailed code structure is pretty same like this document https://remotestack.io/angular-lazy-load-modules-with-dynamic-module-imports-example/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

叫思念不要吵 2025-02-18 13:59:22

@jsbeginner请共享您的lazymodule代码,似乎您需要在lazymodule模块中指定如何配置路由

,然后

const routes: Routes = [
  {
    path: '',
    component: LazyComponent],
  },
];

在lazymodule的导入中添加此代码行

RouterModule.forChild(routes),

@JSBeginner please share your LazyModule code, and it seems you need to specify how you configured routes in the LazyModule module

for example

const routes: Routes = [
  {
    path: '',
    component: LazyComponent],
  },
];

and add this line of code on imports of lazyModule

RouterModule.forChild(routes),
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文