vuejs / Discussion

Vue.js discussion
167 stars 17 forks source link

Routing: how to enable transitions between routes that share the same view? #95

Open sulram opened 9 years ago

sulram commented 9 years ago

Hello! First, thank you for this nice framework! I'm using director.js with vue, as the hackernews clone example. I'm wondering if there is a way to enable transitions between routes that share the same view. In the snippet bellow, transitions are not triggered between #/video/1 and #/video/2, for example.

# the app template
<div class="view" v-component="{{view}}" v-transition></div>

# the route
router.on('/video/:id', function (id) {
    app.view = 'video-view'
    app.params.video = id
})
yyx990803 commented 9 years ago

Unfortunately at the moment you have to do this hack:

router.on('/video/:id', function (id) {
  if (app.view === 'video-view' && app.params.video === id) {
    return // prevent transition on the same id
  }
  app.view = '' // trigger a reset
  Vue.nextTick(function () {
    // wait until the reset kicks in, then set the view again
    app.view = 'video-view'
    app.params.video = id
  })
})
sulram commented 9 years ago

Thanks, Evan @yyx990803