4

Hi i have a requirement to use vue-router4 on vue:^2.6.14 app because i want to use the latest api regarding dynamically registering a route.

Problem: i tried to move vue:^2.6.14 app to vue:3.*.* as there is a requirement of using new vue-router api which supports https://router.vuejs.org/guide/advanced/dynamic-routing.html#adding-nested-routes based on that i asked a question which is un-answered Dynamically registered route is not working when it is just pushed

Note: i tried for complete migration but facing so many errors

My Expection: i want to use vue-router@4 in vue:^2.6.14 only for addRoute('parent',{...Route Object}) method https://router.vuejs.org/guide/advanced/dynamic-routing.html#adding-routes if overriding is possible to get this feature in vue-router3 for vue2 then it is most welcomed!

Note2: after overriding it should work as this example https://codesandbox.io/s/vue-router-test-hvzes5?file=/src/main.js , Note: in main.js only 2 routes are defined.

Issue with vue-router3 for vue2: https://github.com/vuejs/vue-router/issues/1156

Please help me thanks in advance !!

EaBengaluru
  • 131
  • 2
  • 17
  • 59

1 Answers1

6

It's not possible to use vue-router@4 with vue@2. They're incompatible with each other.

And the question assumes that addRoute is only available in vue-router@4, but that's not true. addRoute() was introduced in vue-router@3.5.0, which is compatible with vue@2.

Based on your other question, I think the confusion might be caused by the answer you linked, which only applies to vue-router@2, which does not support addRoute. The workaround provided in that answer would not work properly with vue-router@3, as you had observed.

Here's a demo of your Codesandbox written in vue@2.6.14 with vue-router@3.5.4. Your original code to dynamically add routes was untouched.

tony19
  • 125,647
  • 18
  • 229
  • 307