代码之家  ›  专栏  ›  技术社区  ›  Tom Chiverton

Vue路由器为push()的单个调用更新两次URl

  •  0
  • Tom Chiverton  · 技术社区  · 7 年前

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

    将浏览器URL更新为…#/upload fine。但是

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

    在更新到“…#/”之前,在地址栏中短暂闪烁预期的URL-转换已经起作用,因为我的编辑视图加载,但我必须按两次后退(一次按到/edit/file/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
            }
          ]
        }
      ]
    
    0 回复  |  直到 7 年前
        1
  •  1
  •   Tom Chiverton    6 年前

    因为模板

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

    而不是

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