HarmonyOS路由报错 can‘t find this page pages

最近Harmony的应用开发课程在程序员的圈子里,还是很火的。

于是,看了看自己手机里,21年写的dome,有点跟不上时代了。感觉还是有必要重新捡起来一下,说不定后面恰饭用得上。

在学习HarmonyOS 应用程序框架的时候,对路由页面的跳转进行了实践,前面都挺好,进入项目目录中 entry > src > main > ets > pages > index.ets  ,在pages 目录下创建第二个页面secondPage secondPage 页面正确创建完毕,一切都很丝滑。当我在index页面中 引入router,添加好注册好按钮点击跳转事件,代码如下:

import router from '@ohos.router';
import CommonConstants from '../constants/CommonConstants';
import Logger from '../utils/Logger';
const TAG = '[IndexPage]';
@Entry
@Component
struct Index {
  @State message: string = CommonConstants.INDEX_MESSAGE;
  build() {
    Row() {
      Column() {
        Text(this.message)
          .fontSize(CommonConstants.FONT_SIZE)
          .fontWeight(FontWeight.Bold)
        Blank()
        Button($r('app.string.next'))
          .fontSize(CommonConstants.BUTTON_FONT_SIZE)
          .width(CommonConstants.BUTTON_WIDTH)
          .height(CommonConstants.BUTTON_HEIGHT)
          .backgroundColor($r('app.color.button_bg'))
          .onClick(() => {
            router.pushUrl({
              url: CommonConstants.SECOND_URL,
              params: {
                src: CommonConstants.SECOND_SRC_MSG
              }
            },router.RouterMode.Single).catch((error: Error) => {
              Logger.info(TAG, 'IndexPage push error' + JSON.stringify(error));
            });
          })
      }
      .width(CommonConstants.FULL_WIDTH)
      .height(CommonConstants.LAYOUT_HEIGHT)
    }
    .height(CommonConstants.FULL_HEIGHT)
    .backgroundColor($r('app.color.page_bg'))
  }
}

然后点击按钮,按照路由进行跳转,出问题了,报错如下:

[manifest_router.cpp(GetPagePath)-(0)] [Engine Log] can't find this page pages

[page_router_manager.cpp(StartPush)-(0)] [Engine Log] this uri not support in route push.

提示:找不到路由文件。

开始以为是路由写错了,反复查看官方文档,确认路由无误。突然想起写小程序,一般都需要手动添加页面路由信息。于是:

找到工程目录下 entry > src > main > resources > base > profile > main_pages.json文件,添加pages/SecondPage。路由信息如下:

{
  "src": [
    "pages/Index",
    "pages/SecondPage",
  ]
}

然后就可以完美跳转了

  • 27
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一直在路上_沿路

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值