我们构建了一个 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/