[vuejs/vue-router]Vue-router 偶现在使用$router.go(-1),或者点击浏览器后退按钮 无法渲染页面的问题?

2024-05-08 928 views
6
Version

3.0.0

Reproduction link

https://github.com/vuejs/vue-router/tree/dev/examples

Steps to reproduce

这个问题是偶现的,有一定的概率出现, 问题的现象是 $router.push / $router.replace 能够正常的渲染路由页面, 但是使用$router.go(-1),或者点击浏览器后退按钮 无法渲染, 再用$router.push / $router.replace 能继续进入其他路由页面, 控制台无错误,配置很正常,是hash模式的,Chrome浏览器

What is expected?

使用$router.go(-1),或者点击浏览器后退按钮 能正常渲染

What is actually happening?

无法渲染


初步怀疑,那个hashchange和popstate没有绑定成功事件,我在里面打了断点,没有进到断点里面

回答

1

@h330894169 请问这个问题后来解决了吗?我也遇到了同样的问题,路由push可以正常渲染组件,但路由后退,组件就没有渲染

8

是不是分页导致的?

8

加一遇到这样的问题

8

遇到可同样的问题。真正的原因是什么呢

1

index

// 路由配置
      {
        path: 'eclue',
        component: () => lazyLoadView(import(/* webpackChunkName: "expertprefetch" */ '@/views/expert/eclue/index.vue')),
        name: 'expertEclueList',
        props: true,
        meta: {
          title: '线索库',
          noCache: false,
          key: 'clueLibrary',
          keepUrl: ['eclueedit', 'ecluedetail', 'insti']
        }
      },
      {
        path: 'eclueedit/:id',
        component: () => lazyLoadView(import(/* webpackChunkName: "expertprefetch" */ '@/views/expert/eclue/expert/edit.vue')),
        name: 'eclueedit',
        meta: {
          title: '创建线索专家',
          noCache: true,
          key: 'clueLibrary'
        },
        props: true,
        hidden: true
      },
// 保存操作接口调用成功后
 this.$router.go(-1);

问题是偶现的,很难定位出来是哪里的问题

3

你好,我也遇到同样的问题了,请问你怎么解决的?