AngularJS 1 Restangular GET 剥离 #

AngularJS 1 Restangular GET stripping #

我目前正在 AngularJS 中创建搜索功能 1. 我正在使用 Restangular 以便在我的 JS 前端和 API 之间进行通信。

不过我想知道,AngularJS 或 Restangular 是否会从我的请求中删除某些字符?

我正在使用 Restangular 执行如下获取请求:

Restangular.all('details').get(detail_id).then(function(detailResult) { // etc...

然而,如果 detail_id 设置为:2019 但是当 detail_id 设置为:2019#1

然后 Restangular(我假设)会自动剥离 #1,我在服务器端看不到它。

我是不是在这里犯了一个错误,或者这是使用 Restangular 获取请求的限制,或者这是否按预期工作但我错过了什么?

感谢任何帮助, 谢谢

这是设计使然。 # 之后的部分称为 fragment,它从未发送到服务器,因为它应该仅在客户端使用。

Wikipedia's article on the subject:

The fragment identifier functions differently than the rest of the URI: namely, its processing is exclusively client-side with no participation from the web server

如果 # 实际上是 ID 的一部分,您需要 url 像这样对参数进行编码:

Restangular.all('details').get(encodeURIComponent(detail_id)).then(function(detailResult) { // etc...