HarmonyOS Navigation中getParamByName获取的是所有同个名字的页面参数,如何区分哪个是当前页面?

Navigation 中 getParamByName 获取的是所有同个名字的页面参数,如何区分哪个是当前页面?索引 0 是当前页面吗?

阅读 459
1 个回答

拿到当前页面参数的方式有两种可以作参考:

方法一:在onReady里面拿;

NavDestination(){}
.onReady((context:NavDestinationContext)=>{let Paramus = context.pathInfo.param as string;}) 

方法二:通过byIndex 拿;

this.pathStack?.getParamByIndex(this.pathStack?.size()-1);
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进