HarmonyOS 加载页面时报错Failed to load the content?

报错:Failed to load the content. Cause: {“code”:401}

windowStage.loadContent('pages/NavigationPage', (err, data) => {
  windowStage?.getMainWindowSync()?.setWindowLayoutFullScreen(true); // 界面沉浸式
  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. Data: %{public}s', JSON.stringify(data) ?? '');
});
阅读 541
1 个回答

main\_pages.json 中文件路由缺失,参考如下:

{
  "src": [
  "pages/Index",
  "pages/NavigationPage"
  ]
}

注意:main\_pages.json文件中文件路径不可缺失