useRouter() returns undefined when uses in setup() method in Options API component #2228
-
Reproductionhttps://github.com/brdgm/joan-of-arc-orleans-solo-helper Steps to reproduce the bug
Expected behaviorThe screen of first round should be displayed without errors Actual behaviorIn the browser console, several warnings and an error is displayed:
Additional informationthe problem is, that i suspect the problem is that the route is already created in some way to fill the global $route variable (which cannot be accessed in setup function), and then the call to useRoute in setup fails. but: it worked without problems for the last ~2 years with vue-router versions < 4.3.0. it seems this mixture of Options API component and setup methods is a rare use case, but it's "officially supported" following this documentation: https://vuejs.org/api/composition-api-setup.html#composition-api-setup - bullet #2. this is our use case and worked well for a lot of components. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
If you run Your project uses 4.3.2, but |
Beta Was this translation helpful? Give feedback.
-
yes, indeed - that solves the problem! i was under the assumption that the version in packages.json overwrites the version inherited from brdgm-commons (i'm coming from java backend development where this is the case for transitive maven dependencies). sorry for the noise. |
Beta Was this translation helpful? Give feedback.
If you run
npm list vue-router
, I believe you'll see that you have two versions ofvue-router
installed.Your project uses 4.3.2, but
brdgm-commons
is still pulling in 4.2.5. They both need to use the same Vue Router, otherwise the symbols used byprovide
/inject
won't match.