Vue3“在'vue-router'中找不到导出'createWebHistory,createRouter'
我正在创建一个 Vue3 应用程序,在添加路由器后,我的第一页正在加载,但它完全是空白的。
我收到以下信息
错误:未捕获的类型错误:Object(...) 不是函数
在控制台中:
./src/router/index.js 中的警告“在‘vue-router’中找不到出口‘createRouter’
./src/router/index.js 中的警告“在‘vue-router’中找不到导出‘createWebHistory’
路由器 -> 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 问题
你需要通过 npm 安装路由器
npm install vue-router@next --save
- My issue is that I was incorrectly using `vue-router` and not `vue-router@next`.
THE END
二维码