首页 > 解决方案 > Vue Router 为单次调用 push() 更新 URl 两次

问题描述

这个

this.$router.push({ path: '/upload'});

将浏览器 URL 更新为 ...#/upload 正常。但

this.$router.push( '/edit/file/4' );

在地址栏中短暂闪烁预期的 URL,然后将其更新为“... 4,一次到我真正以前的状态)而不是一次。

为什么 ?我怎样才能让它按我的预期工作?

我的路由器路由是

routes: [
    {
      path: '/',
      name: 'home',
      component: Home,
      children:[
        {
          name: 'upload',
          path:'upload',
          component:HomeUpload
        },

        {
          name: 'edit-file',
          path: 'edit/file/:file_id',
          component:HomeUpload,
          props: true // or field_id prop not filled in
        }
      ]
    }
  ]

标签: vue.jsvue-router

解决方案


因为模板有

<a @click="edit(page)" href="#">Edit</a></td>

代替

<a @click="edit(page)">Edit</a></td>


推荐阅读