我在 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 将更改为:
我尝试了几种方法来纠正这个问题:
使用 ng-href 代替 href,
不使用第一个/(即 href="#/album/{{album.id}}"
)
在 Homestead localhost(Laravel 的 linux vagrant 机器)而不是 Windows 10 上的 localhost 中运行应用程序
任何帮助将不胜感激!
最佳答案
%2F
是 percent-encoding表示正斜杠 /
字符。
此问题与 AngularJS 1.6 更改了 $location
服务中 hash-bang url 的默认值有关。
要恢复到以前的行为:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
有关详细信息,请参阅 SO: angularjs 1.6.0 (latest now) routes not working .
关于AngularJS URL 中的所有斜杠更改为 %2F,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41272314/