Harmony 路由框架 hmrouter 基本使用一

212 阅读1分钟

第一步 设置容器

HMNavigation({
  navigationId: 'mainNavigationId', homePageUrl: 'splash',
  options: {
    standardAnimator: HMDefaultGlobalAnimator.STANDARD_ANIMATOR,
    modifier: this.modifier
  }
});

HMNavigation hmrouter 入口。navigationId 指定容器id。如果全局只有一个HMNavigation,不指定也可以。

homePageUrl 初始页面。

options 暂时没看懂

第二步 给每个页面绑定pageUrl

@HMRouter({pageUrl: "splash"})
@Component
export struct SplashPage {

  build() {
    Stack(){
      Text("Splash")
        .onClick(()=>{
         
      });

    }.alignContent(Alignment.Center)
  }
}

这个地方给SplashPage 绑定了pageUrl 为 splash。

这样当app启动的时候 展示的就是SplashPage