angular - Google Cloud App Engine 上的刷新页面抛出 404

标签 angular google-app-engine google-cloud-platform

我们构建了一个 Angular 6 应用程序并将其部署到 Google Cloud App Engine,该应用程序运行正常。但是,任何时候浏览器使用应用程序根以外的路由刷新时,我们都会收到 404。

这是我们的 app.yaml 文件:

runtime: nodejs8

handlers:
  - url: /
    static_files: dist/song/index.html
    upload: dist/song/index.html
    secure: always

  - url: /(.*)
    static_files: dist/song/\1
    upload: dist/song/(.*)
    secure: always

  - url: /dashboard
    static_files: dist/song/index.html
    upload: dist/song/index.html
    secure: always

错误是 404,表示“未找到处理程序引用的静态文件:song/dashboard/allshoppers”

因此,它在目录结构中寻找静态文件,但这是我们 Angular 应用程序中的一个路由。

最佳答案

您可能需要将每个请求重定向到 index.html,让 Angular 路由器处理所有事情。

- url: /.*
  secure: always
  redirect_http_response_code: 301
  static_files: dist/song/index.html
  upload: dist/song/index.html
  http_headers:
    Strict-Transport-Security: max-age=31536000; includeSubDomains
    X-Frame-Options: DENY

关于angular - Google Cloud App Engine 上的刷新页面抛出 404,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54639904/

相关文章:

angular - PayPal 可以向其他 PayPal 账户发送付款吗?

java - JDK8/JRE8 + Eclipse Luna 上的 Google App Engine 开发

python - 包括httplib2

google-cloud-platform - GCP Cloud Run 通过单独项目中的 2 个服务帐户使用短期凭证调用另一个项目云功能

javascript - 从嵌套数组中获取数据

angular - Ionic 3 Segment ngAfterViewInit 不起作用

javascript - 在 Angular 2 组件上包含 Javascript 文件(jQuery、Bootstrap 等)

python - Google Appengine 上的登录 Hook

google-cloud-platform - 如何在 Terraform 中引用现有组织文件夹或其他资源(适用于 GCP)

firebase - 如何将对象存储在 firebase cloud function RAM 中?