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

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

阅读 461
1 个回答

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

方法一:在onReady里面拿;

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

方法二:通过byIndex 拿;

this.pathStack?.getParamByIndex(this.pathStack?.size()-1);