HarmonyOS 鸿蒙Next app入口EntryAbility中不能加载Navigation页面吗?

发布于 1周前 作者 ionicwang 来自 鸿蒙OS

HarmonyOS 鸿蒙Next app入口EntryAbility中不能加载Navigation页面吗?

在app入口类EntryAbility中加载首页面Index,例如下面代码

onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, ‘testTag’, ‘%{public}s’, ‘Ability onWindowStageCreate’);
windowStage.loadContentByName(‘index’, (err) => {
if (err.code) {
hilog.error(0x0000, ‘testTag’, ‘Failed to load the content. Cause: %{public}s’, JSON.stringify(err) ?? ‘’);
return;
}
hilog.info(0x0000, ‘testTag’, ‘Succeeded in loading the content.’);
});
}<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

使用loadContentByName函数传入一个index,然后在route_map.json中配置如下

{
“routerMap”: [
{
“name”: “editQianPiYiJian”,
“pageSourceFile”: “src/main/ets/pages/EditQianPiYiJian.ets”,
“buildFunction”: “PageBuilder”
},
{
“name”: “index”,
“pageSourceFile”: “src/main/ets/pages/Index.ets”,
“buildFunction”: “PageBuilder”
}
]
}<button style="position: absolute; padding: 4px 8px 0px; cursor: pointer; top: 8px; right: 8px; font-size: 14px;">复制</button>

通过这种方式不能加载Index页面吗?



关于HarmonyOS 鸿蒙Next app入口EntryAbility中不能加载Navigation页面吗?的问题,您也可以访问:https://www.itying.com/category-93-b0.html 联系官网客服。

回到顶部