Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vue+electron 打包后白屏问题 #106

Open
yubaoquan opened this issue Apr 13, 2024 · 0 comments
Open

vue+electron 打包后白屏问题 #106

yubaoquan opened this issue Apr 13, 2024 · 0 comments

Comments

@yubaoquan
Copy link
Owner

yubaoquan commented Apr 13, 2024

原因

因为使用了 vue-router

原理

打包后的app启动后, electron不会自动跳转到 /, 而且路由模式不能使用history
可以在 App.vue 里写死一段东西, 如果能渲染出来, 大概率就是路由问题导致的白屏

解决方案

需要给成hash模式, 而且需要在loadfile的时候指定一下加载的路由

主进程代码:

    mainWindow.loadFile(join(__dirname, '../renderer/index.html'), { hash: '' });

路由代码:

import { createRouter, createWebHashHistory } from 'vue-router';

const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes: [
    // youre routes
  ],
});

export default router;

参考资料

vue-router 或 react-router-dom 开发模式正常,但在构建后无效

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant