2016-08-25 16 views
1

目前,我有一個這樣的網址:我們如何能夠處理URL特殊字符與角JS 2

http://localhost/foo/barbar(2222) 

但是當我嘗試在標籤頁中打開它,它不與角2的工作。它顯示了這樣的錯誤:

Error: Cannot match any routes: '2222'

我們如何處理在AngularJS 2.這個問題要得到的結果,如果我們有編碼的URL打開:http://localhost/foo/barbar%282222%29

+0

你是如何定義你的路線? – JanR

+0

已經定義了。它可以正常工作,當我使用沒有像這樣的特殊字符的url 'http:// localhost/foo/barbar2222' – JeeDee

+0

我們仍然需要查看您的路由定義,以便查看可能出錯的地方。 – ranieuwe

回答

2

在這個momment,這是一個錯誤與路由器組件。有一個解決方法可以解決它。您必須延長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