我使用:
通过“延迟加载”(横向导航)在页面之间导航:
导出const路由= [
{
路径:“”,
loadChildren:“〜/ pages / start-page / start-page.module#StartPageModule”
},
{
路径:“登录”,
loadChildren:“〜/ pages / login / login.module#LoginModule”
},...
使用具有“ clearHistory = true”的RouterExtensions进行导航
当我从“主页”页面导航到另一页并返回“主页”时,我在内存中看到两个组件“ HomeComponent”。当我重复操作时,它们变为3、4、5,.....
答案 0 :(得分:0)
尝试此操作以进行延迟加载路由。
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: "startpage", loadChildren: "~/pages/start-page/start-page.module#StartPageModule" },
{ 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(["startpage"], {
clearHistory: (isIOS) ? true : false,
});
});
}, 500);
}