参考DEMO://Index.ets: import router from '@ohos.router'; let msg: String = 'Index跳来的数据' @Entry @Component struct routerPage { @State message: string = '首页'; build() { Row() { Column() { Text(this.message) .fontSize(60) .fontWeight(FontWeight.Bold) .onClick(() => { this.message = '123' }) Button('跳转页面') .onClick(() => { router.pushUrl({ url: 'pages/routerSec', params: { src: msg } }) }) } .width('100%') } .height('100%') } } //routerSec.ets import router from '@ohos.router'; @Entry @Component struct routerSec { @State message: string = 'Hello 123'; @State src: string = (router.getParams() as Record<string, string>)['src']; build() { Row() { Column() { Text(this.message) .fontSize(60) .fontWeight(FontWeight.Bold) Text(this.src) .margin({ bottom: 20 }) Button('返回首页') .onClick(() => { router.back(); }) } .width('100%') } .height('100%') } }参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-router-V5\#基于ts扩展的声明式开发范式
参考DEMO:
参考链接:https://developer.huawei.com/consumer/cn/doc/harmonyos-references-V5/js-apis-router-V5\#基于ts扩展的声明式开发范式