1. 在router文件里面没有定义history 项目中的router文件夹 index.js
import { createRouter } from "vue-router";
import HomeView from "../views/HomeView.vue";
const routes = [
{
path: "/",
name: "home",
component: HomeView,
}
];
const router = createRouter({
routes,
});
export default router;
2.解决方法 import createWebHistory, 加上 history:createWebHistory(process.env.BASE_URL),
import { createRouter, createWebHistory } from "vue-router";
import HomeView from "../views/HomeView.vue";
const routes = [
{
path: "/",
name: "home",
component: HomeView,
}
];
const router = createRouter({
history: createWebHistory(),
routes,
});
export default router;