electron + vue3 + ts 打包后安装打开白屏解决

使用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;

这样可以啦,再次打包安装后打开后一切正常!

相关推荐
代码煮茶4 分钟前
Vue3 组件库二次封装实战 | 基于 Element Plus 封装企业级 UI 组件库
前端·javascript·vue.js
shen_5 分钟前
JS语法:生成器和可迭代对象
javascript
之歆37 分钟前
DAY_11JavaScript BOM与DOM深度解析:底层原理与工程实践(上)
开发语言·前端·javascript·ecmascript
逆yan_44 分钟前
🧭 基于 pnpm Workspace 和 Turborepo 的 Monorepo 最佳实践
前端·javascript·架构
Nturmoils1 小时前
书签真正难的不是收藏,而是找回来:我是怎么做这个 Chrome 插件的
javascript·后端·浏览器
HYCS1 小时前
用pixijs实现fabricjs(三):对象继承链和自定义对象
前端·javascript·canvas
biubiubiu_LYQ1 小时前
萌新小白基础篇之JS预编译
javascript
ZC跨境爬虫1 小时前
跟着 MDN 学 HTML day_60:(表单与按钮技能测试实战)
服务器·前端·javascript·数据库·ui·html
ljt27249606611 小时前
Vue笔记(四)--组件基础
前端·vue.js·笔记
张元清1 小时前
React 里不用 setTimeout 的计时器写法:useTimeout、useInterval、useCountDown 和 useRafFn
前端·javascript·面试