2014-07-22 38 views
0

以下代碼片段不會將我重定向到指定頁面(redirectUrl) - 而是將字符串「localhost」的前綴redirectUrl前綴。

我最終重定向到"localhost/http://localhost/example/page".

我怎樣才能避免這種情況?

var redirectUrl = "http://localhost/example/page"; 
$location.path(redirectUrl); //redirects to "localhost/http://localhost/example/page".` 
$scope.$apply(); 

回答

1

您需要將路徑修改爲相對路徑而不是絕對路徑。所以它會是這樣的:

var redirectUrl = "/example/page"; 
$location.path(redirectUrl); //redirects to "http://localhost/example/page".` 
0

angular's $location服務基於相對url。

重定向到您可以使用的絕對url。

window.location.href="http://localhost/example/page"; 或使用角度的$window $window.location.href="http://localhost/example/page";

相關問題