【问题标题】:Angular 6 Routing Ignore API calls from routingAngular 6路由忽略来自路由的API调用
【发布时间】:2018-10-25 15:39:11
【问题描述】:

我有 Angular 6 应用程序和 WebAPI。我已经在 IIS 上和 Angular 应用程序下部署了 Angular 应用程序,我为 API 创建了应用程序。

类似的东西

IIS 
  |
  |-Angular6App(port:443)
       |
       |-ServiceAPI

这背后的想法是使用相同的 DNS。因此,当调用 https://Angular6App.com 时,它应该加载 Angular 应用程序。如果https://Angular6App.com/ServiceApi/api/cntlr/id被调用,它应该得到数据(意思是调用api服务)。

所以现在当我调用https://Angular6App.com/ServiceApi/api/cntlr/id 时,它正在从 Angular 应用程序加载默认路由。实际上我想在调用 api 时跳过角度路由。

Angular 应用中的路由

[
  { path: '', redirectTo: 'A', pathMatch: 'full' },
  { path: 'A', component: AComponent, canActivate: [AuthGuard] },
  { path: 'B', component: BComponent, canActivate: [AuthGuard] },
]

请让我知道我是否可以这样做以及如何做到这一点?

谢谢 --cc

【问题讨论】:

  • 分享你的代码。
  • 我认为使用 Web Api 部署 Angular 生产静态文件是一种很好的技术,因为我已经使用 Spring Boot 和 Express 部署了 Angular 应用程序,两者都采用了它们部署静态文件的独特方式.而我们只需要通过 ng build —prod 将构建 Angular 应用程序生成的文件,即 dist 文件夹中的文件复制到 speingboot 或 express 的这个静态区域
  • 您的应用中是否定义了其他路由?感觉就像你有一个匹配 ** 路径并使用默认路由的组件或重定向到默认路由。
  • @DanielWSrimpel 除了 {path: 'logout', component: LogoutComponent} 之外,我没有指定任何其他路由。
  • @AbhishekKumar 我确实是从 dist 复制的。 API 和 Angular 在部署为不同的站点/应用程序时有效。问题是当我在 IIS 中的 Angular 下创建 API 应用程序时。(调用 API 时重定向到默认路由)

标签: angular asp.net-web-api


【解决方案1】:

我得到了这个工作。 在 IIS 上,使用 URL 重写忽略 serviceapi 的模式。

在主应用程序(顶级,即 Angular6App)上设置 URL 重写以忽略任何匹配 */ServiceAPI 的 URL

Screenshot of URL rewrite setting

希望这对那里的人有所帮助。

【讨论】:

  • 您可能还想将规则添加到 angular web.config:跨度>
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-22
  • 1970-01-01
  • 2013-02-21
相关资源
最近更新 更多