首页 新闻 赞助 找找看

vue项目 this.$router.go(-1) 无法返回上一页 点击两次后能返回 但出现 路由错误问题

0
[已解决问题] 解决于 2021-06-08 17:16

代码:

//button
<button class="btn back p-cu-p" @click="goback">GoBack</button>

//function
goback () {
this.$router.go(-1)
},
//route
{
path: '/certification',
name: 'CertifictionIndex',
component: () => import('@/views/CustomerManagement/certificationIndex.vue'),
children: [
{
path: '/',
name: 'Certifiction',
component: () => import('@/views/CustomerManagement/certification.vue'),
},
{
path: 'detail',
name: 'CertifictionDetail',
component: () => import('@/views/CustomerManagement/certificationDetail.vue'),
},
],
}
问题补充:

路由栈中存在两条以上路由记录
用 this.$router.push(‘path’)可以正常跳转 ,但this.$router.go(-1)无法正常返回上一条路由

AUSER的主页 AUSER | 菜鸟二级 | 园豆:206
提问于:2021-06-04 11:00
< >
分享
最佳答案
0

将button 改为其它标签

AUSER | 菜鸟二级 |园豆:206 | 2021-06-08 17:15
其他回答(3)
0

那你有放 0试试嘛

| 园豆:453 (菜鸟二级) | 2021-06-04 14:13

go(0)只是刷新当前路由 ,试过 window.history.back() 、window.history.go(-1)都有这个问题
用 this.$router.push(‘path’)可以正常跳转 ,但this.$router.go(-1)无法正常返回上一条路由

支持(0) 反对(0) AUSER | 园豆:206 (菜鸟二级) | 2021-06-04 14:36
0

搜索你的问题时看到的,可能是命名错误
https://blog.csdn.net/DemoJx/article/details/101113860

holy0619 | 园豆:202 (菜鸟二级) | 2021-06-04 16:54

感谢评论 , 不过路由命名感觉没啥问题
附上源码

支持(0) 反对(0) AUSER | 园豆:206 (菜鸟二级) | 2021-06-04 18:14
1

<button> 加个 type="button" 属性,不然默认情况下是提交按钮,触发表单提交了

<button class="btn back p-cu-p" @click="goback" type="button">GoBack</button>
by.Genesis | 园豆:2712 (老鸟四级) | 2021-06-07 10:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册