Vue-router: Allow specifying different transitions for navigation and popstate

Created on 7 Jun 2015  路  8Comments  路  Source: vuejs/vue-router

Sometimes different page transitions are needed when clicking a link vs. clicking the back button.

feature request group[current route information]

Most helpful comment

Until this get's an official solution, the method I've settled for is setting a "depth" meta property for each route. Then when the route changes, check whether the new route depth is higher or lower than the previous. If it's higher, transition from right, if it's lower (going back) transition from left.

Not ideal and could be a nightmare to maintain, but get's the job done for simple implementations.

  { 
    name: 'categories',
    path: '/categories',
    component: categories,
    meta: { depth: 1 },
  },
  { 
    name: 'category',
    path: '/categories/:category/',
    component: category,
    meta: { depth: 2 },
  }
<transition :name="transitionDirection">
  <router-view></router-view>
</transition>



md5-c536852c0f23604e907f91cd3a77bfa1



data() {
  return {
    transitionDirection: 'slide-left',
  }
},
watch: {
  '$route' (to, from) {
    const toDepth = to.meta.depth
    const fromDepth = from.meta.depth
    this.transitionDirection = toDepth < fromDepth ? 'slide-right' : 'slide-left';
  }
}



md5-c536852c0f23604e907f91cd3a77bfa1



.slide-left-enter,
.slide-right-leave-active {
  transform: translate3d(100%, 0, 0);
  opacity: 0;
}

.slide-right-enter,
.slide-left-leave-active {
  transform: translate3d(-100%, 0, 0);
  opacity: 0;
}



md5-027f316cfc1f05693c8c45be9599dc8c



watch: {
  '$route' (to, from) {
    const toDepth = to.path.split('/').length
    const fromDepth = from.path.split('/').length
    this.transitionDirection = toDepth < fromDepth ? 'slide-right' : 'slide-left'
  }
}

All 8 comments

Does this mean we can have transitions that go back and forth between pages in a single page app?

I would be happy to see that. Maybe we could eventually get to do something like this?
http://www.appcoda.com/wp-content/uploads/2015/03/vid08.gif

+1
I would love a way to specify to vue-router that transitions has to be done in reverse order

Is there any updated?

How about this feature now ?

Until this get's an official solution, the method I've settled for is setting a "depth" meta property for each route. Then when the route changes, check whether the new route depth is higher or lower than the previous. If it's higher, transition from right, if it's lower (going back) transition from left.

Not ideal and could be a nightmare to maintain, but get's the job done for simple implementations.

  { 
    name: 'categories',
    path: '/categories',
    component: categories,
    meta: { depth: 1 },
  },
  { 
    name: 'category',
    path: '/categories/:category/',
    component: category,
    meta: { depth: 2 },
  }
<transition :name="transitionDirection">
  <router-view></router-view>
</transition>



md5-c536852c0f23604e907f91cd3a77bfa1



data() {
  return {
    transitionDirection: 'slide-left',
  }
},
watch: {
  '$route' (to, from) {
    const toDepth = to.meta.depth
    const fromDepth = from.meta.depth
    this.transitionDirection = toDepth < fromDepth ? 'slide-right' : 'slide-left';
  }
}



md5-c536852c0f23604e907f91cd3a77bfa1



.slide-left-enter,
.slide-right-leave-active {
  transform: translate3d(100%, 0, 0);
  opacity: 0;
}

.slide-right-enter,
.slide-left-leave-active {
  transform: translate3d(-100%, 0, 0);
  opacity: 0;
}



md5-027f316cfc1f05693c8c45be9599dc8c



watch: {
  '$route' (to, from) {
    const toDepth = to.path.split('/').length
    const fromDepth = from.path.split('/').length
    this.transitionDirection = toDepth < fromDepth ? 'slide-right' : 'slide-left'
  }
}

Transitions are extremely clumsy when using the swipe back gesture on iOS because they fire after the user has already reached the destination.

Being able to disable transitions when a forward/back button or browser gesture is used would be _very_ helpful.

Transitions are extremely clumsy when using the swipe back gesture on iOS because they fire after the user has already reached the destination.

Being able to disable transitions when a forward/back button or browser gesture is used would be _very_ helpful.

Have you found a work-around? I'm really struggling with transitions and swipe back gestures on iOS.

Have you found a work-around? I'm really struggling with transitions and swipe back gestures on iOS.

I never found a workaround, just this issue

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gil0mendes picture gil0mendes  路  3Comments

shinygang picture shinygang  路  3Comments

druppy picture druppy  路  3Comments

alexstanbury picture alexstanbury  路  3Comments

Atinux picture Atinux  路  3Comments