angular - 我们如何使用 Angular 处理 URL 中的特殊字符

标签 angular typescript router

目前,我有一个像这样的网址:

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 存储库中检查该问题。

https://github.com/angular/angular/issues/4895

关于angular - 我们如何使用 Angular 处理 URL 中的特殊字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39138499/

相关文章:

ios - 避免在 Restkit 路由器上进行 uri 编码

java - 如何通过 Java 应用程序启动/停止无线路由器?

javascript - 如何使用该数组中对象的键对 typescript 数组进行分组?

css - Angular 2中背景图像url的属性属性绑定(bind)

angular - NgIf 和零 : Why is the template not being rendered?

javascript - 编译后的 typescript 文件位于 Angular 2 项目中的什么位置?

javascript - TypeScript 中 React StatelessComponent 的 DefaultProps

angular - RxJS - 分享由 'expand' 产生的无限流

angular - ngx-捕获 : Unable to capture <img> inside the screen capture area

ubuntu - 未配置接口(interface) eth0