onWindowStageCreate(windowStage: window.WindowStage): void {
// Main window is created, set main page for this ability
hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');
windowStage.loadContent('pages/Page2', (err) => {
if (err.code) {
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
return;
}
AppStorage.setAndLink('windowStage', windowStage);// 关键代码
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.');
});
}
相关示例代码如下,请看下是否符合要求:
1、页面一:
2、页面二:
3、EntryAbility文件: