目前,我有一个像这样的网址:
http://localhost/foo/barbar(2222)
但当我尝试在选项卡中打开它时,它不适用于 Angular。它显示这样的错误:
Error: Cannot match any routes: '2222'
我们如何在 Angular 中处理这个问题。要获得结果,就像我们使用编码的 url 打开它一样: http://localhost/foo/barbar%282222%29
最佳答案
目前,这是 Router 组件的一个错误。有一个解决方法可以解决这个问题。您必须扩展 encodeUri
。
encodeURIComponent(str) {
return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
return '%' + c.charCodeAt(0).toString(16);
});
}
在 Angular 的 GitHub 存储库中检查该问题。
关于angular - 我们如何使用 Angular 处理 URL 中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138499/