问题描述
我在AngularJS路由方面遇到了很大的问题.
I'm having a massive problem with AngularJS routing.
直到最近,通过以下路线一切都很好:
Up until recently everything has been fine with the following route:
$routeProvider.when('/album/:albumId', {
controller: 'albumPageController',
templateUrl: 'views/album.html'
});
并使用href:
<a href="/#/album/{{album.id}}">Link</a>
但是,现在所有的斜杠都被编码为%2F
.
However, now all of the slashes are being encoded into %2F
.
因此,当我单击链接或在浏览器中键入localhost:8000/#/album/1
时,URL更改为:
So when I click the link, or type localhost:8000/#/album/1
into the browser, the URL is changed to:
我已经尝试了几种方法来纠正此问题:
I've tried several things to correct this:
使用ng-href代替href,不使用第一个/(即href="#/album/{{album.id}}"
)在Homestead本地主机(Laravel的Linux流浪者机器)上运行应用程序,而不是在Windows 10上运行本地主机
Using ng-href instead of href,Not using the first / (ie href="#/album/{{album.id}}"
)Running the app in Homestead localhost (Laravel's linux vagrant machine) instead of localhost on Windows 10
任何帮助将不胜感激!
推荐答案
%2F
是% -encoding 表示正斜杠/
字符.
此问题与AngularJS 1.6更改了$location
服务中的hash-bang url的默认值有关.
This problem is related to the fact that AngularJS 1.6 has changed the default for hash-bang urls in the $location
service.
要还原为以前的行为,请执行以下操作:
To revert to the previous behavior:
appModule.config(['$locationProvider', function($locationProvider) {
$locationProvider.hashPrefix('');
}]);
有关更多信息,请参见 SO:angularjs 1.6.0 (最新)路由不起作用.
For more information, see SO: angularjs 1.6.0 (latest now) routes not working.
这篇关于AngularJS URL中的所有斜杠已更改为%2F的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!