使用electron + vue3 + ts技术栈,开发桌面应用,打包后安装打开是白屏,开发环境却没事
解决方案:很大可能是路由问题,把history模式改为hash模式:
将createWebHistory改为createWebHashHistory
原代码
bash
import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import HomeView from "../views/Home/HomeView.vue";
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "home",
component: HomeView
},
];
const router = createRouter({
history: createWebHistory(process.env.BASE_URL),
routes,
});
export default router;
改为Hash模式:
bash
import { createRouter, createWebHashHistory, RouteRecordRaw } from "vue-router";
import HomeView from "../views/Home/HomeView.vue";
const routes: Array<RouteRecordRaw> = [
{
path: "/",
name: "home",
component: HomeView
},
];
const router = createRouter({
history: createWebHashHistory(process.env.BASE_URL),
routes,
});
export default router;
这样可以啦,再次打包安装后打开后一切正常!