import Vue from 'vue'
import VueRouter from 'vue-router'
const Home = () => import('../views/home/Home')
const Category = () => import('../views/category/Category')
const Cart = () => import('../views/cart/Cart')
const Profile = () => import('../views/profile/Profile')
Vue.use(VueRouter)
const routes = [
{
Path: '',
redirect: '/home'
},
{
path: '/home',
component: Home
},
{
path: '/category',
component: Category
},
{
path: '/cart',
component: Cart
},
{
path: '/profile',
component: Profile
}
]
const router = new VueRouter({
routes,
mode: 'history'
})
export default router
There is no problem with using vue2 and vue3 in this code, but we are now vue4, and many things have changed. For example, for this routing problem, the error reported in the vscode terminal is: “export ‘default’ (imported as’ vuerouter ‘) was not found in’ Vue router ‘
The result of Baidu translation is that the default value of “export” cannot be found in “Vue router” (imported as “vuerouter”)
The errors reported in the browser are: Uncaught TypeError: Cannot read property ‘use’ of undefined
The result of Baidu translation is: uncapped typeerror: the undefined attribute “use” cannot be read
Let’s go to the terminal first. The main keys are “vuerouter” and “Vue router”, which we have imported and installed here
Then the problem may not be here. Next, let’s look at the problem on the browser. Its key is “use”. According to our understanding, “use” should be a function defined in Vue. Then we press and hold Ctrl and left click in vscode to find its definition. The result is no response, so the problem may appear here, We can also go to the folder and look for it. Here I provide vue2 and the folder where we have problems
This is vue2’s
This is a problem
If you have an idea, you can also look in the two imported files. There is no definition, which is the reason for the error. The solution is to use another method to use routing.
import {createRouter, createWebHistory} from "vue-router";
const Home = () => import('../views/home/Home')
const Category = () => import('../views/category/Category')
const Cart = () => import('../views/cart/Cart')
const Profile = () => import('../views/profile/Profile')
const routes = [
{
Path: '',
redirect: '/home'
},
{
path: '/home',
component: Home
},
{
path: '/category',
component: Category
},
{
path: '/cart',
component: Cart
},
{
path: '/profile',
component: Profile
}
]
const router = createRouter({
history: createWebHistory(),
routes
})
export default router
This level is solved.
Read More:
- Echars 5.0 Import Error: “export ‘default’ (imported as ‘echarts’) was not found in ‘echarts’
- [Solved] Vue3 Error: export ‘createRouter‘ was not found in ‘vue-router‘
- Attempted import error: ‘mobx-react‘ does not contain a default export (imported as ‘observer‘).
- The imported project “c:\Microsoft.Cpp.Default.props” was not found
- [Solved] swiper Error: The requested module ‘react’ is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by importing the default export
- Error starting vue project these dependencies were not found:create in ./src/router/modules/md.js
- Yaml is installed, and the error YAMLLoadWarning is reported as soon as the code runs: calling yaml.load() without Loader=… is deprecated, as the default Loader is unsafe.
- k8s kubernetes ingress error: endpoints “default-http-backend“ not found
- [Solved] Could not identify launch activity: Default Activity not found Error while Launching activity
- [Solved] Could not identify launch activity: Default Activity not found Error while Launching activity
- [Solved] FileUploadException: the request was rejected because no multipart boundary was found
- C# Error: Import “google/protobuf/timestamp.proto“ was not found or had errors. [How to Solve]
- How to Solve VScode 2022 error: msvcp110d.dll not found
- [Solved] A needed class was not found. This could be due to an error in your runpath. Missing class: scala/co
- Remember an android app startup error Error running: Default Activity not found
- RuntimeError: ONNX export failed: Couldn‘t export operator aten::upsample_bilinear2d
- Cordova – CordovaError: Promise rejected with non-error: ‘ios-deploy was not found
- JSP error: The superclass “javax.servlet.http.HttpServlet” was not found on the Java Build Path
- [Solved] Instantiation of ‘sdram_model_plus‘ failed. The design unit was not found.