[英]Is there a new feature to load lazy routing module in Angular 15?
在我的 Angular 12 應用程序中,我使用下面的代碼預加載所有路由(包括所有惰性模塊路由)。 盡管configLoader
是私有屬性,但我的代碼運行良好。 到目前為止,我還沒有聽說過任何替代方法來做到這一點。
(<any>router).***configLoader***.load(injector, route).subscribe({
next: (moduleConf: any) => {
const children: any = [];
children.push(...moduleConf.routes.map((childRoute: any) => childRoute));
routes.push({ path: currentPath, children });
children.map((childRoute: any) => {
if (childRoute.children && childRoute.children.length > 0) {
childRoute.children.map((x: any) => {
preload(currentPath, x);
});
}
});
}
});
當我把我的項目升級到Angular 15后,我不能再編譯它了,因為沒有更多的configLoader
(看起來相應的屬性被刪除了)。 我已經用谷歌搜索了幾天,但還沒有找到任何解決方案。 你們中的任何人都可以給我一些關於如何為 Angular 15 重寫上述代碼的建議嗎? 我感謝您的幫助!
我只是偶然發現了這個問題並找到了一個似乎工作正常的解決方案。
只需更改第一行:
(<any>router).configLoader.load(injector, route).subscribe({
有了這個:
(<any>router).navigationTransitions.configLoader.loadChildren(injector, route).subscribe({
我不知道引擎蓋下發生了什么,我只是在尋找具有相同簽名和相似名稱的 function。 所以在某些場景下可能會出現一些意想不到的行為。
不過,就我而言,它工作正常。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.