在';VUE-ROUTER';中找不到VUE3;EXPORT';createWebHistory,createRouter';
我正在创建一个Vue3应用程序,添加路由器后,我的第一个页面正在加载,但它完全是空白的。
我收到以下邮件
错误:未捕获类型错误:对象(...)不是函数
在控制台中:
找不到./src/router/index.js";EXPORT‘createRouter’中的警告 在‘VUE-ROUTER’ ./src/router/index.js";导出‘createWebHistory’中的警告不是 在‘VUE-ROUTER’中找到
路由器->;index.js
import { createWebHistory, createRouter } from "vue-router";
...
const routes = [{
path: "/user/create",
name: "createUser",
component: createUser,
},
{
path: "/users",
name: "listUser",
component: listUser,
meta: { requiresAuth: true }
},
{
path: "/user/show/:id",
name: "showUser",
component: showUser,
meta: { requiresAuth: true }
},
{
path: "/user/update/:id",
name: "updateUser",
component: updateUser,
},
{
path: "/login",
name: "login",
component: Login
},
{
path: "/register",
name: "register",
component: Register
},
{
path: "/users/bearer",
name: "bearer",
component: bearer,
meta: { requiresAuth: true }
}
]
const router = createRouter({
history: createWebHistory(),
routes,
});
router.beforeEach((to, from, next) => {
const requiresAuth = to.matched.some(record => record.meta.requiresAuth);
const isAuthenticated = firebase.auth().currentUser;
console.log("isauthenticated", isAuthenticated);
if (requiresAuth && !isAuthenticated) {
next("/login");
} else {
next();
}
});
export default router;
解决方案
在这里找到了答案:
Stackoverflow question
您需要通过NPM安装路由器
npm install vue-router@next --save
相关文章