Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

在route上面增加isEventChange属性判断是否是事件改变的路由还是调用方法改变的路由 #1916

Closed
agileago opened this issue Dec 1, 2017 · 17 comments

Comments

@agileago
Copy link

agileago commented Dec 1, 2017

What problem does this feature solve?

有时候需要知道是否是用户主动调用方法改变的路由还是点击导航栏或者左滑返回改变的路由,以处理动画效果,比如ios上面用户左滑返回上一个路由,需要在beforeEach里面判断是调用方法触发的还是 hashchange或者 popstate事件触发的,来处理要不要拥有返回动画,如果是左滑返回的话就不用做动画效果了

What does the proposed API look like?

router.beforeEach((to, from, next) => {
  if (to.isEventChange) {
    // 不处理动画 
  } else {
    // 处理返回动画
  }
})
@posva
Copy link
Member

posva commented Dec 2, 2017

Are you asking for a way to know if the action came from a user action or not?

@agileago
Copy link
Author

agileago commented Dec 2, 2017

yes

@posva
Copy link
Member

posva commented Dec 2, 2017

Sorry, I meant if the action came from clicking somewhere.
What may be possible is to add some flag if the navigation is called from a push or similar but I'm unsure of this being very reliable because using next should remove this flag but some people may be expecting to have it.
For the moment it's still doable in userland because as the dev, you know best where the action came from

@agileago
Copy link
Author

agileago commented Dec 4, 2017

only browser trigger router change should add this prop. because the vue-router handle the router event. i think it should be apply on vue-router

@posva
Copy link
Member

posva commented Dec 4, 2017

Can you give some examples to better understand, please 🙂 ?

@agileago
Copy link
Author

agileago commented Dec 4, 2017

IOS left slide back

when you do a transition in router-view. you should judge the behavior is back or forward. like this

<template>
  <div>
    <h2>transition router-view</h2>
    <transition :name="viewTransition" :css="!isEventChange">
       <router-view />
    </transition>
  </div>
</template>


<script>
  export default {
    data () {
      return {
        viewTransition: 'forward',
        isEventChange: false
      }
    }
  }
</script>

when you click the browser back navigator. you should do a back transition. but when you do left slide back using hand. you don't want to do transition in router-view. so far. we use overwrite the router methods to hack this. but it is not a perfect solution.

see example
https://vux.li/demos/v2/?x-page=v2-doc-home#/

the code solution
https://github.com/airyland/vux/blob/v2/src/main.js#L147

@posva
Copy link
Member

posva commented Dec 4, 2017

So, you only need to know if popstate was used to navigate? (#14)

@agileago
Copy link
Author

agileago commented Dec 4, 2017

almost. i don't need know the direction. just want to know the router change is the event change or user change (by click or js). but hachchange should also handle the same behavior

@posva
Copy link
Member

posva commented Dec 5, 2017

But vue-router cannot guess if the action comes from a user action or not 🙁

@agileago
Copy link
Author

agileago commented Dec 5, 2017

of course vue-router can do it. wait a time. i will do a pr.

@posva
Copy link
Member

posva commented Dec 5, 2017

If it's patching push and other methods, that's not enough.
Functionally speaking, what is the feature you want to achieve?

@agileago
Copy link
Author

agileago commented Dec 5, 2017

I just know the router change is by the user click browser navigator(include ios swipe back) or by router method execute (push, go, forward, back, replace, include router-link)

@h330894169
Copy link

这个问题有新进展了吗?@ @agileago

@cqgsm
Copy link

cqgsm commented Mar 2, 2018

同问,这个问题有进展了吗?

@luckymore
Copy link

Why not add the isEventChange prop by yourself?

@icefee
Copy link

icefee commented Jun 12, 2018

同问,这个问题有进展了吗?

@posva
Copy link
Member

posva commented Jul 10, 2018

knowing if the action came from a user action or not is not doable in vue-router. Not even sure if it's possible in userland as well for all cases, but should be possible in specific scenarios

@posva posva closed this as completed Jul 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants