在URI中包含斜线字符“/”的标识符

我正在使用Express ,MongoDB和Angular创build一个应用程序,我在MongoDB中的一个文档的标识符是_id ='20161007 / COMPANY-00 / CL / 01-01'

我想通过使用标识符的REstful API从Angular获取数据:

var _id = '20161007/COMPANY-00/CL/01-01'; this.$http.get('/api/datadays/' + _id) .then(response => {....} 

但结果是:

angular.js:11881 GET http:// localhost:9000 / api / datadays / 20161007 / COMPANY-00 / CL / 01-01 404(Not Found)

有没有在标识符中使用斜杠的方法来处理node / express中的restful API?

谢谢

你应该看看编码URI组件和解码URI组件 。

前端代码:

 var _id = encodeURIComponent('20161007/COMPANY-00/CL/01-01'); this.$http.get('/api/datadays/' + _id) .then(response => {....} 

后端代码:

 app.get('/api/datadays/:id', function(req, res) { let id = decodeURIComponent(req.params.id) ... })