firebase - 火力基地 | 重新加载后在当前目录中找不到 index.html
问题描述
我在 firebase 上安装了 Vue3。在开发模式下它按预期运行:
/startPage
是 vue-router 中的默认页面:
router.beforeEach((to, from, next) => {
const publicPages = ['/startPage'];
const authRequired = !publicPages.includes(to.path);
if (authRequired && store.getters.isLoggedIn === "") {
console.log("Not logged in...");
router.push('/startPage');
} else {
next();
}
//this.username = store.getters.getUser.username;
});
现在在firebase上部署它时,访问时会出现页面/startPage
,但是在重新加载页面时我得到:
This file does not exist and there was no index.html found in the current directory or 404.html in the root directory.
编辑:firebase.json
{
"hosting": {
"public": "dist/",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
解决方案
对于单页应用程序,所有路径都需要利用重写,因为 SPA 生成单个 HTML 文档:如在文档中找到并在此处回答
"rewrites":[
{
"source":"**",
"destination":"/index.html"
}
]
如果您需要添加其他路径,则应优先将它们放在通配符之前。
可以在 VueJS文档中找到相同的内容。
推荐阅读
- flutter - 颤动我如何隐藏滚动上的容器
- c - 类型转换为 Float 的指针
- ios - 将当前时间向上舍入到下一个 30 分钟间隔
- java - 为什么在JPanel中添加组件,面板可以显示,但是当组件先添加到框架时,面板不能显示
- visual-studio - Visual Studio Code 2019 不允许我使用 c++ 17 功能
- firebase - Firestore firebase admin listCollections 按字段值获取
- flutter - 接收类型为“列表”的运行时错误
>' 不是类型“列表”的子类型 >' 图表颤振 - c# - 初学者制作控制台应用游戏,遇到属性继承问题
- python - Ubuntu 18.04 烧瓶无法到达端口 5000 上的 api 端点
- android - 为什么我的代码对我的 android studio 中不存在的文件显示错误?