gpt4 book ai didi

angular - akka-http + angular2 路由

转载 作者:太空狗 更新时间:2023-10-29 19:31:05 25 4
gpt4 key购买 nike

我正在尝试从 akka-http(scala rest 框架)提供 angular2(rc3) 应用程序。由于路由,它不起作用。当请求时,spray 尝试将 /my/endpoint/declared/in/angular 找到为普通资源。我应该怎么做?

使用简单的静态网页,没有路由(动态链接),这很容易:

path("app") {
getFromResource("my-app/index.html")
} ~ getFromResourceDirectory("my-app")

每次找不到请求的资源时,我都尝试提供 index.html:

path("app") {
getFromResource("my-app/index.html")
} ~ getFromResourceDirectory("my-app") ~ getFromResource("my-app/index.html")

但它破坏了相关链接(当我请求 /app/my/endpoint 时,我得到了 index.html,它试图从 /app/my/endpoint/styles 下载 styles.css .css 而不是 /app/styles.css)

我想知道在其他http服务器上是怎么做到的。

最佳答案

我解决了这个问题。它可能不是最佳的,但效果很好。

在你放置的喷雾配置中:

path("ui") { //the same prefix must be set as base href in index.html
getFromResource("abtest-ui/index.html")
} ~ pathPrefix("ui") {
getFromResourceDirectory("abtest-ui") ~
getFromResource("abtest-ui/index.html")
}

在 index.html 中:

<base href="/ui/">

总结:

  • 请求/ui/服务于index.html
  • 请求 /ui/someResourceFile.css 提供此资源
  • 请求 /ui/AnythingThat/IsNotA/ResourceFile 服务于 index.html 并且 Angular 路由处理它

关于angular - akka-http + angular2 路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38145976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com