首页 > 解决方案 > 火力基地 | 重新加载后在当前目录中找不到 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/**"
    ]
  }
}

标签: firebasevue.js

解决方案


对于单页应用程序,所有路径都需要利用重写,因为 SPA 生成单个 HTML 文档:如在文档中找到并在此处回答

        "rewrites":[
            {
                "source":"**",
                "destination":"/index.html"
            }
        ]

如果您需要添加其他路径,则应优先将它们放在通配符之前。

可以在 VueJS文档中找到相同的内容。


推荐阅读