c***@qq.com
c***@qq.com
  • 发布:2020-12-10 10:28
  • 更新:2023-10-21 21:00
  • 阅读:3218

【报Bug】uni.setTabBarItem设置参数pagePath,无法跳转到该页面

分类:uni-app

产品分类: uniapp/App

PC开发环境操作系统: Windows

PC开发环境操作系统版本号: win10

HBuilderX类型: 正式

HBuilderX版本号: 2.9.8

手机系统: Android

手机系统版本号: Android 10

手机厂商: 华为

手机机型: mate10

页面类型: vue

打包方式: 云端

项目创建方式: HBuilderX

示例代码:

js代码

uni.setTabBarItem({  
                    index: 0,  
                    "pagePath": "pages/reader/home",  
                    "text": "读者",  
                    "iconPath": "static/images/tabbar/book.png",  
                    "selectedIconPath": "static/images/tabbar/book-fill.png"  
                });  
                uni.switchTab({  
                    url: '/pages/reader/home'  
                })

pages.json

"tabBar": {  
        "color": "#333333",  
        "backgroundColor": "#F8F8F8",  
        "selectedColor": "#2979ff",  
        "list": [{  
                "pagePath": "pages/store/home",  
                "text": "首页",  
                "iconPath": "static/images/tabbar/home.png",  
                "selectedIconPath": "static/images/tabbar/home-fill.png"  
            },  
            {  
                "pagePath": "pages/activity/activityList",  
                "text": "活动",  
                "iconPath": "static/images/tabbar/activity.png",  
                "selectedIconPath": "static/images/tabbar/activity-fill.png"  
            },  
            {  
                "pagePath": "pages/book/bookList",  
                "text": "书籍",  
                "iconPath": "static/images/tabbar/book.png",  
                "selectedIconPath": "static/images/tabbar/book-fill.png"  
            },  
            {  
                "pagePath": "pages/test/videoCompress",  
                "text": "拼书",  
                "iconPath": "static/images/tabbar/group-book.png",  
                "selectedIconPath": "static/images/tabbar/group-book-fill.png"  
            },  
            {  
                "pagePath": "pages/test/menu",  
                "text": "我的",  
                "iconPath": "static/images/tabbar/mine.png",  
                "selectedIconPath": "static/images/tabbar/mine-fill.png"  
            }  
        ]  
    }

操作步骤:

如代码所示

预期结果:

跳转到替换掉的pagePath路径

实际结果:

页面没有反应

bug描述:

问题平台:H5/APP

pages.json的tabBar预先设置了5个页签。

另外根据业务需要,更换不同的角色,需要替换掉原来页签的路径。通过uni.setTabBarItem设置pagePath后,页面没有发生变化,没有跳转。

已做成demo,可下载附件。

2020-12-10 10:28 负责人:无 分享
已邀请:
DCloud_UNI_Anne

DCloud_UNI_Anne

uni.setTabBarItem下,pagePath是页面绝对路径,要写成pagePath: '/pages/more/more'

  • c***@qq.com (作者)

    感谢回复。我大概知道问题出在哪了。我给的demo其实还不够全面。


    比如,我当前在登录页,从后端提交请求后,获取到角色,需要刷新即将跳转过去的tabbar的pagePath。在跳过去之前,先在登录页写了uni.setTabBarItem。这样写就跳不过去了。


    可能是还未跳转到tabbar所在的页面之前,就更新了它的配置,就无法生效。

    2020-12-10 15:55

c***@qq.com

c***@qq.com (作者)

我重新上传了刚刚所描述的问题的demo

c***@qq.com

c***@qq.com (作者)

@DCloud_UNI_Anne 麻烦再确认下哦

c***@qq.com

c***@qq.com (作者)

问题还是存在,麻烦官方再确认下

  • 4***@qq.com

    你好,这个问题有解决吗

    2022-08-05 18:02

4***@qq.com

4***@qq.com

1、你的"pagePath": "pages/reader/home", 首先 改成pagePath:'/pages/reader/home' 绝对路径是需要再前面有一条杠。
2、其次 如果你进行跳转,你写到了别人的函数下面,是无法启动,你可以写在success 里面,才会进行启动。再次,如果你写在成功的回调函数里,是没有意义的,你改的是navtab 不是 改好之后就立刻跳转,你需要让用户点击进行跳转。
3、因此参考第一个方案,即可满足你的需求。

2***@qq.com

2***@qq.com

你们这个变更后跳转路径的问题解决了吗,目前我也遇到了这个问题 , 如有解决方案,麻烦告知

4***@qq.com

4***@qq.com - 我很懒

还是没有解决吗?pagePath不生效

uni.setTabBarItem({  
                    index: 0,  
                    iconPath: "static/images/tabbar-011.png",  
                    selectedIconPath: "static/images/tabbar-001.png",  
                    pagePath: "/pages/nurse/list",  
                    text: "接单",  
                    success(res){  
                        console.log("res: ", res);  
                        uni.switchTab({  
                            url: "/pages/nurse/list"  
                        })  
                    }  
                })

要回复问题请先登录注册