【问题标题】:Spring Gateway how to route deep SPA linksSpring Gateway 如何路由深度 SPA 链接
【发布时间】:2021-01-22 07:06:34
【问题描述】:

我有一个从 Spring Gateway 路由的 Angular 应用程序。根路由正常工作,但是当您深入嵌套路由时,它返回未找到状态。在Angular docs 和这个tutorial 上说你必须重写任何未找到的路由到 /index.html 但我在 Spring Cloud Gateway 文档中没有找到任何关于如何配置它的参考。

application.yml

      - id: teams-frontend
        uri: lb://teams-frontend
        predicates:
          - Path=/teams,/teams/**
        filters:
          - StripPrefix=1
#         - RewritePath=/.*, /index.html  ## This breaks existing link resources such as the scripts linked on the index.html

angular 应用找不到时如何回退到 index.html?

【问题讨论】:

    标签: angular spring gateway


    【解决方案1】:

    我开发了一个custom filter。如果请求包含标头“Accept: text/html”,则请求路径将被 /index.html 覆盖

    - id: teams-frontend
        uri: lb://teams-frontend
        predicates:
          - Path=/teams,/teams/**
        filters:
          - StripPrefix=1
          - SPA
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-05
      • 2016-10-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多