Aurelia + Whatwg-fetch: 调用错误 API 服务

Aurelia + Whatwg-fetch: Call wrong API service

我正在使用 Aurelia 开发 Web 应用程序。我对 Aurelia 和 Whatwg-fetch 有疑问。

API 的亲戚 url 是 api/post/load/{id}。当我使用获取客户端调用此 API 时,我认为它获取当前 url 来调用 (http://localhost:9000/detail/api/post/load/{id})。我不知道为什么会这样。有时它会正确调用 API 的 url,有时则不会。

您访问应用的 url 是 http://localhost:9000/details。由于您没有在其中包含井号 (#),我假设 details 部分不是由 Aurelia 添加的,这让我相信您可以在 /details 访问应用程序本身.

如果是这样,问题是 不是 在 API 的 url 前加上斜杠(/ ), 得到的 url 将以 url+api url 为基数,即 localhost:9000/details + api/post/load/iddetailsapi 之间的斜杠是在构建最终绝对值 url 时代表您添加的。在这种情况下,您需要做的就是在 api url 前加一个斜杠,例如:/api/post/load/{id}.