小编典典

AngularJS URL中的所有斜杠已更改为%2F

angularjs

我在AngularJS路由方面遇到了一个大问题。

直到最近,通过以下路线一切都很好:

$routeProvider.when('/album/:albumId', {
    controller: 'albumPageController',
    templateUrl: 'views/album.html'
});

并使用href:

<a href="/#/album/{{album.id}}">Link</a>

但是,现在所有的斜杠都被编码为%2F

因此,当我单击链接或键入localhost:8000/#/album/1浏览器时,URL更改为:

http:// localhost:8000 /#%2Falbum%2F1

我已经尝试了几种方法来纠正此问题:

href="#/album/{{album.id}}"在Windows 10上使用ng-
href代替href,不使用第一个/(即)在Homestead本地主机(Laravel的Linux流浪者机器)而不是本地主机中运行应用程序

任何帮助将非常感激!


阅读 503

收藏
2020-07-04

共1个答案

小编典典

%2F是正斜杠字符的百分比编码/

此问题与AngularJS 1.6更改了$location服务中的hash-bang url的默认设置有关。

要恢复到以前的行为:

appModule.config(['$locationProvider', function($locationProvider) {
  $locationProvider.hashPrefix('');
}]);
2020-07-04