我正在尝试制作一个在 App Engine 标准环境上运行的 Angular 2 应用程序。在应用程序内导航时,它与以下 app.yaml
配置一起工作:
handlers:
- url: /api/.*
script: _go_app
- url: (.*)/
static_files: static\1/index.html
upload: static
- url: (.*)
static_files: static\1
upload: static
我可以单击从 /
到 /clients
或 /clients/234234
的链接,它工作正常。
但是,如果我在非基本路径中刷新浏览器,例如http://myapp.appspot.com/clients/234234
然后我收到 404 错误。我想我需要从我认为 (.*)/
和 (.*)
的所有路径提供我的 index.html
做。
如何设置我的处理程序/应用程序以便我可以使用 HTML5 路由而不让这种情况发生?
最佳答案
我有一堆需要提供的静态文件,所以我先添加了它们的映射。我还(最重要的)改变了 index.html 的服务方式:
handlers:
- url: /api/.*
script: _go_app
- url: /(.*\.svg)
static_files: static/\1
upload: static/(.*\.svg)
- url: /(.*\.js)
static_files: static/\1
upload: static/(.*\.js)
- url: /(.*\.map)
mime_type: application/octet-stream
static_files: static/\1
upload: static/(.*\.map)
- url: (.*)/
static_files: static/index.html
upload: static
- url: (.*)
static_files: static/index.html
upload: static
关于google-app-engine - 如何在页面刷新时使 Angular 2 路由与 App Engine 一起工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39312010/