当前位置:   article > 正文

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

can't find this page pages

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

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

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

  1. import router from '@ohos.router';
  2. import CommonConstants from '../constants/CommonConstants';
  3. import Logger from '../utils/Logger';
  4. const TAG = '[IndexPage]';
  5. @Entry
  6. @Component
  7. struct Index {
  8. @State message: string = CommonConstants.INDEX_MESSAGE;
  9. build() {
  10. Row() {
  11. Column() {
  12. Text(this.message)
  13. .fontSize(CommonConstants.FONT_SIZE)
  14. .fontWeight(FontWeight.Bold)
  15. Blank()
  16. Button($r('app.string.next'))
  17. .fontSize(CommonConstants.BUTTON_FONT_SIZE)
  18. .width(CommonConstants.BUTTON_WIDTH)
  19. .height(CommonConstants.BUTTON_HEIGHT)
  20. .backgroundColor($r('app.color.button_bg'))
  21. .onClick(() => {
  22. router.pushUrl({
  23. url: CommonConstants.SECOND_URL,
  24. params: {
  25. src: CommonConstants.SECOND_SRC_MSG
  26. }
  27. },router.RouterMode.Single).catch((error: Error) => {
  28. Logger.info(TAG, 'IndexPage push error' + JSON.stringify(error));
  29. });
  30. })
  31. }
  32. .width(CommonConstants.FULL_WIDTH)
  33. .height(CommonConstants.LAYOUT_HEIGHT)
  34. }
  35. .height(CommonConstants.FULL_HEIGHT)
  36. .backgroundColor($r('app.color.page_bg'))
  37. }
  38. }

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

[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。路由信息如下:

  1. {
  2. "src": [
  3. "pages/Index",
  4. "pages/SecondPage",
  5. ]
  6. }

然后就可以完美跳转了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/繁依Fanyi0/article/detail/307126
推荐阅读
相关标签
  

闽ICP备14008679号