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

the beforeRouteLeave event of vue's first component is not trigger #1951

Closed
Francecil opened this Issue Dec 22, 2017 · 2 comments

Comments

Projects
None yet
2 participants
@Francecil

Francecil commented Dec 22, 2017

Version

3.0.1

Reproduction link

https://jsfiddle.net/gahing/c61ng9of/7/

Steps to reproduce

(1)open https://jsfiddle.net/gahing/c61ng9of/7/

(2)Press the back button of the browser immediately

(3)Or wait for 2S ,browser will alert('main beforeRouteLeave happened')

my english is poor , that is chinese version as follows:

(1)打开该网址

(2)立刻按浏览器的后退按钮

(3)或者等待2s 出现alert弹框('main beforeRouteLeave happened')

What is expected?

When 'Main' component is mounted,and the function of setTimeout is not happened,Press the back button of the browser immediately. I
wish that the beforeRouteLeave event is triggered.

What is actually happening?

It is not happen。bug when the code "this.$router.push('/user')" run, will trigger beforeRouteLeave


now, my solution is add component named 'BeforeMain' before Main component.
when BeforeMain'mounted trigger,run "this.$router.push({name:'main'})"
Add 'beforeEach':
router.beforeEach((to, from, next) => {
// gameview的
if (to.name === 'beforemain' && from.name === 'main') {
router.go(-1)
next(false)
} else {
next()
}
})
Thus,while current component is 'Main' ,you press back button of brower, you can trigger 'beforeRouteLeave'
But , it 's so trouble

Chinese version:
将第一个组件前再增加一个beforemain组件,做一次push跳转。这样main可以正常触发beforeRouteLeave

@posva

This comment has been minimized.

Show comment
Hide comment
@posva

posva Dec 23, 2017

Member

The setTimeout still happens even though you go back, there nothing wrong here

Member

posva commented Dec 23, 2017

The setTimeout still happens even though you go back, there nothing wrong here

@posva posva closed this Dec 23, 2017

@Francecil

This comment has been minimized.

Show comment
Hide comment
@Francecil

Francecil Dec 25, 2017

setTimeout can happen,but the back evnet of browser can't happen

Francecil commented Dec 25, 2017

setTimeout can happen,but the back evnet of browser can't happen

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment