【问题标题】:Nativescript (angular) not finding module for lazy loadingNativescript(角度)找不到延迟加载的模块
【发布时间】:2019-03-11 17:44:43
【问题描述】:

我正在尝试在我的应用程序中延迟加载模块。此示例应该适用于 Angular,但它会引发以下错误:

Computed path '/Users/faridgarciayala/Library/Developer/CoreSimulator/Devices/D5EE2284-8088-43A1-A703-1A5C7021DF42/data/Containers/Bundle/Application/0D994956-6311-438F-B459-98BA7424EF1A/routingexample.app/app/one/one.module'

它显然是试图从模拟器中获取模块。

这是我的repo

完整的错误日志:

CONSOLE ERROR file:///app/tns_modules/@angular/core/bundles/core.umd.js:15768:28: ERROR Error: Uncaught (in promise): Error: Could not find module './one/one.module'. Computed path '/Users/faridgarciayala/Library/Developer/CoreSimulator/Devices/D5EE2284-8088-43A1-A703-1A5C7021DF42/data/Containers/Bundle/Application/0D994956-6311-438F-B459-98BA7424EF1A/routingexample.app/app/one/one.module'. require@[native code] file:///app/tns_modules/tns-core-modules/globals/globals.js:81:39 ZoneAwarePromise@file:///app/tns_modules/nativescript-angular/zone-js/dist/zone-nativescript.js:902:37 import@file:///app/tns_modules/tns-core-modules/globals/globals.js:79:27 loadAndCompile@file:///app/tns_modules/@angular/core/bundles/core.umd.js:18403:33 loadModuleFactory@file:///app/tns_modules/@angular/router/bundles/router.umd.js:3702:50 load@file:///app/tns_modules/@angular/router/bundles/router.umd.js:3690:56 file:///app/tns_modules/@angular/router/bundles/router.umd.js:2693:55 _tryNext@file:///app/tns_modules/rxjs/inte<…>

【问题讨论】:

  • 请在这里分享相关代码

标签: javascript angular web angular2-nativescript


【解决方案1】:

尝试这个延迟加载路由。

app-routing.module.ts :-

import { NgModule } from "@angular/core";
import { Routes } from "@angular/router";
import { NativeScriptRouterModule } from "nativescript-angular/router";

const routes: Routes = [
{ path: "", redirectTo: "/login", pathMatch: "full" },
{ path: "library", loadChildren: "~/pages/library/library.module#LibraryModule" },
{ path: "login", loadChildren: "~/pages/login/login.module#LoginModule" }
]

@NgModule({
imports: [NativeScriptRouterModule.forRoot(routes)],
exports: [NativeScriptRouterModule]
})
export class AppRoutingModule { }

重定向代码:-

import { NgZone } from "@angular/core";
import { isIOS } from "tns-core-modules/platform";
import { RouterExtensions } from "nativescript-angular/router";

constructor(private zone: NgZone,
private _routerExtensions: RouterExtensions){ }

gotoStartPage() {
setTimeout(() => {
    this.zone.run(() => {
        this._routerExtensions.navigate(["library"], {
            clearHistory: (isIOS) ? true : false,
        });
    });
}, 500);
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-07
    • 1970-01-01
    相关资源
    最近更新 更多