访问路径/reading/一人之下/第1话1.姐姐1
打印的目录结果为/reading/%E4%B8%80%E4%BA%BA%E4%B9%8B%E4%B8%8B/%E7%AC%AC1%E8%AF%9D1.%E5%A7%90%E5%A7%901
显然无法正常访问目录
解决方法使用urlencode模块
var urlencode=require(“urlencode”);
url="/reading/%E4%B8%80%E4%BA%BA%E4%B9%8B%E4%B8%8B/%E7%AC%AC1%E8%AF%9D1.%E5%A7%90%E5%A7%901";
var param = encodeURI("/reading/一人之下/第1话1.姐姐1");//尝试加密结果是否和乱码后的一致i
console.log(url);
console.log(param);
打印结果
/reading/%E4%B8%80%E4%BA%BA%E4%B9%8B%E4%B8%8B/%E7%AC%AC1%E8%AF%9D1.%E5%A7%90%E5%A7%901
/reading/%E4%B8%80%E4%BA%BA%E4%B9%8B%E4%B8%8B/%E7%AC%AC1%E8%AF%9D1.%E5%A7%90%E5%A7%901
既然加密后的结果与乱码结果一致,那么问题就简单了
将乱码解码一次便可
var urlencode=require(“urlencode”);
url="/reading/%E4%B8%80%E4%BA%BA%E4%B9%8B%E4%B8%8B/%E7%AC%AC1%E8%AF%9D1.%E5%A7%90%E5%A7%901";
var param = encodeURI("/reading/一人之下/第1话1.姐姐1");
console.log(url);
console.log(param);
var param=urlencode.decode(url,“UTF-8”);//解码为UTF-8格式
console.log(param);//打印结果为/reading/一人之下/第1话1.姐姐1
结果成立,问题解决!
至于安装urlencode若出现问题
请参考https://blog.csdn.net/GBrain/article/details/104876360