簡體   English   中英

Angular 8 - 模塊的延遲加載不起作用

[英]Angular 8 - Lazy Loading of Module not working

https://stackblitz.com/edit/angular-qbbhgp所示,我試圖實現一個非常簡單的路由,其中​​涉及模塊的延遲加載。 當我點擊“鏈接”時,它似乎不起作用。 我希望看到“Student Page”這個詞出現,但它沒有發生。

請注意,我希望解決方案涉及使用 import api(延遲加載模塊的較新語法)

這是因為您還沒有在學生模塊中添加路由。

你的 stackblitz 的分支: https ://stackblitz.com/edit/angular-zrnrxj

student 模塊在聲明路由時需要使用.forChild() ,因為它是一個子模塊。

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

@NgModule({
  imports: [
    CommonModule,
    RouterModule.forChild(routes)
  ],
  declarations: [StudentComponent]
})
export class StudentModule { }

您還沒有為Student.routing.module提供Routes嗎?

由於您已經指導了student.module ,但您可能沒有從那里提供您所展示的組件。

如果您尚未創建到Student.routing.module ,請創建一個並在同一模塊中提供默認路由。

const routes: Routes = [

  {path: '', component:StudentComponent } ];

您必須定義延遲加載模塊的路由並指定延遲加載模塊的根組件。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM