Migrating vue-router from v3 to v4 results in unexpected changes to Router signature from createRouter #1975
-
Reproductionn/a Steps to reproduce the bugHowdy folks, this is a bit of a strange one, but bear with me and I'll try and explain whats going on because I'm stumped and really need some help. Steps
Expected behaviorExisting properties from Actual behaviorAny code using So for instance, if I have the following code:
The application will fail with a runtime error saying Additional informationSome interesting things I've noticed while trying to figure this issue out;
This is where things get really hazy for me, because for all intents and purposes on the surface the signatures should be the same, with a Here is our utility function, migrated to vue-router v4... if something there could be playing havoc with the resolutions:
Environment info;Vue version: Vue-router version: Vue CLI version: Webpack version (embedded in the Vue CLI): Any help or guidance on this would be greatly appreciated <3 |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I've figured out what was happening here. Basically in the latest version of vue-router, the Here's a diff of what I mean: -const myQueryProperty = router.currentRoute.query.customProperty;
+const myQueryProperty = router.currentRoute.value.query.customProperty I've raised a PR (see #1976) to update the migration docs, hopefully this is useful to someone else! |
Beta Was this translation helpful? Give feedback.
I've figured out what was happening here.
Basically in the latest version of vue-router, the
currentRoute
object was changed to a reactive object, which meant that to access the underlying properties likequery
,params
orfullPath
in a normal javascript file (as opposed to a Vue template file), you needed to add a.value
to the property chain.Here's a diff of what I mean:
I've raised a PR (see #1976) to update the migration docs, hopefully this is useful to someone else!