【问题标题】:How do I make Angular 2 routing work with App Engine on page refresh?如何在页面刷新时使 Angular 2 路由与 App Engine 一起使用?
【发布时间】:2016-09-03 22:55:12
【问题描述】:

我正在尝试制作一个在 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 路由而不让这种情况发生?

【问题讨论】:

    标签: google-app-engine angular


    【解决方案1】:

    我有一堆需要提供的静态文件,所以我先添加了它们的映射。我还(最重要的是)改变了 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
    

    【讨论】:

      猜你喜欢
      • 2017-10-06
      • 2015-08-14
      • 2016-12-22
      • 1970-01-01
      • 1970-01-01
      • 2019-01-01
      • 2020-07-10
      • 2017-02-01
      • 1970-01-01
      相关资源
      最近更新 更多