首页 > 解决方案 > firebase托管后下拉链接不起作用

问题描述

我正在关注 Udemy 的角度教程。我可以在本地主机中打开引导导航栏下拉链接,但在托管到 firebase 后无法打开(其他导航栏链接按预期工作)。请帮忙

我在 404 错误之后降落在他身上:

404 Page Not Found 在这个网站上找不到指定的文件。请检查 URL 是否有错误,然后重试。为什么我会看到这个?此页面由 Firebase 命令行界面生成。要修改它,请编辑项目配置的公共目录中的 404.html 文件。

索引.html:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Oshop</title>
  <base href="/">

  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="icon" type="image/x-icon" href="favicon.ico">
<link rel="stylesheet" href="styles.ffb6f1d88864b80c037e.css"></head>
<body>
  <app-root></app-root>
<script type="text/javascript" src="runtime.a66f828dca56eeb90e02.js"></script><script type="text/javascript" src="polyfills.2f4a59095805af02bd79.js"></script><script type="text/javascript" src="main.10b7c76792e4769182f0.js"></script></body>
</html>

firebase.json:

{
  "hosting": {
    "public": "dist",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**"
    ]
  }
}

标签: angularfirebasefirebase-hosting

解决方案


我通过将我的 firebase.json 文件修改为以下内容来修复它:

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

推荐阅读