vue-router installation error

problems encountered

When installing vue-router, I found the following error:

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/vue
npm ERR!   vue@"^2.6.14" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer vue@"^3.2.0" from [email protected]
npm ERR! node_modules/vue-router
npm ERR!   vue-router@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

Among them, we pay special attention to: npm ERR! peer vue@"^3.2.0" from [email protected]

Because after February 7, 2022, the default version of vue-router is version 4, and vue-router4 can only be used in vue3, and only
vue-router3 can be used in vue 2

If vue-router4 is forced to be installed into vue2, the above error will be reported;

Solution

Correct installation method of router in vue2:

npm i vue-router@3

Guess you like

Origin blog.csdn.net/qinqinzqq/article/details/125743503