解决VUE proxy pathRewrite 无效的无奈方法
用VUE的时候代理访问后台服务的时候,PathRewrite 总是不生效,
//前端的路径是:
const url='/abcservice/testapi'
//目标的路径是:
https://www.abc.com/service/testapi
proxy配置如下:
"proxy": {
"/abcservice": {
"pathRewrite": {"^/abcservice": ""},
"target": "https://www.abc.com/service/",
"changeOrigin": true,
"secure": true
},
上述配置各种尝试,最终后台得到的url都是:
https://www.abc.com/service/abcservice/testapi
希望通过 pathRewrite 替换掉 abcservice,但是在实际测试中,却无论如何都无法去掉,也就是说pathRewrite 始终不生效。
最后实在是没辙了,采用了后台替换的方式,在后台,将收到的访问路径进行了替换,去掉了abcservice。
strReplace('/abcservice/','/', requesturl);
最终得到
https://www.abc.com/service/testapi。
这不是最好的方案,但是总归凑合用。
如果有大神看到这个问题,希望能给出 让replacePath生效的法子。