【问题标题】:App Engine on page refresh gives 404 for my angular2 project?App Engine 页面刷新为我的 angular2 项目提供 404?
【发布时间】:2017-02-18 01:04:29
【问题描述】:

这个问题与How do I make Angular 2 routing work with App Engine on page refresh? 非常相似,但我没有足够的评论点数,而且它说不要在答案中提出问题。

除了它是appspot上的静态托管站点,使用了angular cli dist文件夹之外,其他问题都是一样的:

Project
|
+--dist
   |
   +--index.html
   +--inline.js
   +--inline.map
   +--main.bundle.js
   +--main.map
   +--styles.bundle.js
   +--styles.map

+--app.yaml
+--index.yaml

我尝试将我的 app.yaml 更改为类似于上面链接的 Dan 的答案,但无法解决?这是 app.yaml 文件:

application: 
version: 
runtime: python27
threadsafe: true
api_version: 1

handlers:
- url: /(.*\.js)
  static_files: dist/\1
  upload: dist/(.*\.js)

- url: /(.*\.map)
  mime_type: application/octet-stream
  static_files: dist/\1
  upload: dist/(.*\.map)

- url: /
  static_files: dist/index.html
  upload: dist/index.html

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

谢谢

【问题讨论】:

    标签: google-app-engine angular


    【解决方案1】:

    试试这个处理程序:

    - url: /(.*\.(gif|png|jpg|css|js)(|\.map))$
     static_files: dist/\1
     upload: dist/(.*)(|\.map)
    
    - url: /(.*)
      static_files: dist/index.html
      upload: dist/index.html
    

    如果您的应用使用更多,请在第一个处理程序中添加文件扩展名。

    适用于我的应用...

    【讨论】:

    • 为它的工作干杯。是否有一些文档向您展示了如何为 angular2 应用程序创建此处理程序?我一直在到处寻找
    • 对于单页应用,您希望将任何 url 重定向到 index.html,通常具有特定文件扩展名的资产除外。当您了解这一点以及如何编写正则表达式时,就很简单了。
    • 谢谢,这对我有用。我不得不添加一些其他的字体扩展,比如 ttf
    猜你喜欢
    • 1970-01-01
    • 2019-05-22
    • 2017-11-22
    • 2016-12-13
    • 1970-01-01
    • 2020-07-06
    • 1970-01-01
    • 2019-11-27
    相关资源
    最近更新 更多