angular - 带有角度路由的 Spring Cloud Gateway
问题描述
我有一个 Spring Cloud Gatway,它路由到一个 Angular 应用程序,该应用程序托管在 localhost:9092/admin 下的 Tomcat 服务器上。这是我的网关配置
server:
port: 9091
spring:
cloud:
gateway:
routes:
- id: adminui
uri: http://localhost:9092
predicates:
- Path=/admin/**
这运作良好。现在我开始使用 Angular 路由并添加了子 URL,例如
/admin/users
在我在浏览器中点击刷新之前,或者当我尝试直接导航到给定的 url 之前,这一直很好。然后我得到一个
404-NotFound
来自网关,因为在托管 Angular“dist”的 Tomcat 文件夹中找不到此资源。
解决方案
实际上这是一个普遍的问题,在 Tomcat 上托管这样的 SPA 页面。因此,当您将 dist 文件夹部署到 tomcat 服务器上时,与此处的 angular2 路由不起作用的问题相同
解决方案是告诉网关将请求路由到 Tomcat 中 index.html 的任何 Angular 路由
routes:
- id: adminuisub
uri: http://localhost:9092
predicates:
- Path=/admin/users/**
filters:
- SetPath=/admin/index.html
推荐阅读
- css - 如何使flexbox子项从父类填充父项的宽度
- mysql - mysql安装问题。(mysql本地服务启动和停止。一些服务...)
- kotlin - 如何在 Kotlin Compose 桌面中加载图像?
- r - 是否可以使用 case_when 函数或使用不同的函数在列中有多个变量名(不是数字)
- powershell - 如何使用powershell获取这样的标题
- flutter - 颤振与 setInt 共享首选项问题
- python - Pybind11 - 转换抽象继承的类元素列表
- java - 如何检查自定义对象列表是否包含另一个列表中具有相同属性的所有元素?
- r - 如何使用 R 中的函数输入更改 URL 的一部分?
- ruby-on-rails - Rails 6 如何解决 ActionView::Template::Error (Webpacker 在 public/packs/manifest.json 中找不到应用程序