Google Cloud App Engine 中的 Angular 7 路由不起作用



我已经向Google Cloud App Engine发布了一个角度7应用程序。

索引页正在加载,但子目录给了我

Error: Not Found
The requested URL /admin was not found on this server.

这是我的应用程序.yaml:

runtime: nodejs10

env_variables:
environment: "--prod"
handlers:
  - url: /
    static_files: dist/XXX/index.html
    upload: dist/XXX/index.html
  - url: /
    static_dir: dist/XXX/
  - url: /.*
    secure: always
    script: auto

编辑:我终于弄清楚了app.yaml中的路由如何适用于Angular Applications。这是我的工作app.yaml:

runtime: nodejs10
env_variables:
  environment: "--prod"
handlers:
- url: /
  secure: always
  static_files: dist/index.html
  upload: dist/.*
- url: /(.*.js)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/1
  upload: dist/.*.js
- url: /(.*.css)
  secure: always
  redirect_http_response_code: 301
  static_files: dist/1
  mime_type: text/css
  upload: dist/.*.css
- url: /.*
  secure: always
  static_files: dist/index.html
  upload: dist/.*

我认为如果您的资源文件只有 js 和 css,则处理程序中的路由规则工作正常。如果您有图像文件、音频文件等,则必须对正则表达式使用更通用的路由规则:

handlers:
  - url: /
    secure: always
    static_files: www/index.html
    upload: www/index.html
  #  Routing rules for resources, css, js, images etc. Any file with format filename.ext
  - url: /(.*.(.+))$
    secure: always
    static_files: www/1
    upload: www/(.*.(.+))$
  #  Routing rule for Angular Routing
  - url: /(.*)
    secure: always
    static_files: www/index.html
    upload: www/index.html

思路是相同的,但从语法上讲,任何具有 filename.* 格式的文件的通配符匹配将处理所有资源文件。

相关内容

  • 没有找到相关文章

最新更新