angular - Spring Gateway 如何路由深度 SPA 链接
问题描述
我有一个从 Spring Gateway 路由的 Angular 应用程序。根路由正常工作,但是当您深入嵌套路由时,它返回未找到状态。在Angular 文档和本教程上,您必须重写任何未找到的路由到 /index.html,但我在 Spring Cloud Gateway 文档中没有找到任何关于如何配置它的参考。
应用程序.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
找不到时,角度应用程序如何回退到 index.html?
解决方案
我开发了一个自定义过滤器。如果请求包含标头“Accept: text/html”,则请求路径将被 /index.html 覆盖
- id: teams-frontend
uri: lb://teams-frontend
predicates:
- Path=/teams,/teams/**
filters:
- StripPrefix=1
- SPA
推荐阅读
- python-3.x - 通过 SQLalchemy URI 调用 RDS 时 Lambda 函数卡住
- azure - ADB2C refresh_token 总是在一天后过期
- html - 在悬停 CSS 上选择第一个子 img 标签
- assembly - 在 8086 中将标志值存储在变量中 - 汇编语言
- r - 带有 DT 和 data.table 的闪亮绑定输入类在 R Shiny 中丢失
- robotframework - 如何在 Robot Framework 中执行延迟变量替换?
- python - 验证数据时出现 ValueError
- next.js - 没有服务器端渲染功能的导入模块
- azure - 在故障恢复时刷新 Redis 密钥
- python - 使用 python 对数学运算进行基准测试