在Angular2中使用特殊字符“:”进行路由

时间:2017-05-16 16:45:18

标签: angular url routing

我的网址就像 abc.org/books/sort:created/direction:desc abc.org/books/sort:mostviewed/direction:desc

abc.com/books/schools/sort:created/direction:desc abc.com/books/schools/sort:mostviewed/direction:desc

我希望我的sort参数包含“created”或“mostviewed”但角度routerLink将“:”转换为“%3A”并且我的链接变为

abc.org/books/sort%3Acreated/direction%3Adesc abc.org/books/sort%3Amostviewed/direction%3Adesc

abc.com/books/schools/sort%3Acreated/direction%3Adesc abc.com/books/schools/sort%3Amostviewed/direction%3Adesc

和“created”或“mostviewed”未分配给params排序。

如何在路由和路径中逃避“:” routerLink。

1 个答案:

答案 0 :(得分:0)

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

你必须像这样扩展encodeUri

encodeURIComponent(str) {
    return encodeURIComponent(str).replace(/[!'()*]/g, function (c) {
        return '%' + c.charCodeAt(0).toString(16);
    });
}