[2.0] beforeRouteEnter's next(vm => { }) callback not always works
See original GitHub issueThis bug this about different path with the same component.
index.vue
<template>
<div>
<router-link :to="{ path: '/' }">root</router-link>
<router-link :to="{ path: '/a' }">a</router-link>
<router-link :to="{ path: '/b' }">b</router-link>
</div>
</template>
beforeRouteEnter: (to, from, next) => {
console.log(111)
next(vm => {
console.log(222, vm) // <- this not always be printed
});
}
main.js
import Index from './index.vue'
Vue.use(VueRouter)
var routes = [
{ path: '/', component: Index },
{ path: '/a', component: Index },
{ path: '/b', component: Index },
]
var router = new VueRouter({
routes: routes
})
Then access / and just switch between a and b, “222” never be printed. I already tested it on a new empty project generated by vue-cli. I’ll upload that if you need.
Issue Analytics
- State:
- Created 7 years ago
- Reactions:6
- Comments:18 (5 by maintainers)
Top Results From Across the Web
beforeRouteEnter next(vm => ()) callback not firing - Ionic Forum
next callback in beforeRouteEnter is not firing. Simple example: beforeRouteEnter(to, from, next) { next(vm => { alert('test'); }); },.
Read more >Next() is not being called on beforeRouteUpdate using the ...
I am using the same vue-component to display data that I'm fetching with axios. After clicking on a link the ajax-request is fetching...
Read more >Adam Wathan no Twitter: "Does anyone understand why it's ...
Alright have a complete example that works the way I want now. In hindsight it makes sense that in the beforeRouteEnter next() callback...
Read more >Undefined template variables in `beforeRouteEnter` next (vm ...
siteId) next(vm => { vm.site = site }) }. I had expected from the docs that the value would be set on the...
Read more >In-component Navigation Guard callback not working: Nuxt JS ...
Next step is to add your middleware to your page pages/results/index.vue like ... Always read the nuxt docs first because nuxt does not...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Seems to still have a problem, anyone with me?
BTW, using a
key
attribute with the route path is a workaround for your problem (:key="$route.path"
on therouter-view
element) https://jsfiddle.net/pyqchnrd/