报错:Uncaught TypeError: Cannot read properties of undefined (reading ‘use’)
Reason: Vue-router version problem. In vue-router3, the router plug-in can be installed in router/index.js, but 4 is not supported.
Solution:
1. In router/index.js, export two functions {createRouter, createWebHistory}.
Use createRouter to create a routing object.
Use the createWebHistory function to assign a value to the history attribute. Because it is vue-router4, it must have a history attribute, otherwise an
Uncaught error will be reported. Error: Provide the “history” option when calling “createRouter()”: https://next.router.vuejs.org/api/#history.
2. Then install the routing plug-in in the main.js file
router/index.js
import {
createRouter, createWebHistory} from 'vue-router'
const routes = [
{
path: '/hello',
component: () => import('../components/HelloWorld')
}
]
export default createRouter({
history: createWebHistory(),
routes
})
main.js
import {
createApp } from 'vue'
import App from './App.vue'
import router from './router'
const app = createApp(App)
app.use(router)
app.mount('#app')