question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[2.0] beforeRouteEnter's next(vm => { }) callback not always works

See original GitHub issue

This 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:closed
  • Created 7 years ago
  • Reactions:6
  • Comments:18 (5 by maintainers)

github_iconTop GitHub Comments

11reactions
dehypnosiscommented, Sep 4, 2017

Seems to still have a problem, anyone with me?

7reactions
posvacommented, Oct 26, 2016

BTW, using a key attribute with the route path is a workaround for your problem (:key="$route.path" on the router-view element) https://jsfiddle.net/pyqchnrd/

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found