AngularJS URL 中的所有斜杠都更改为 %2F [英] AngularJS All slashes in URL changed to %2F

查看:38
本文介绍了AngularJS URL 中的所有斜杠都更改为 %2F的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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:

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

我尝试了几种方法来纠正这个问题:

I've tried several things to correct this:

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

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

任何帮助将不胜感激!

推荐答案

%2Fpercent-encoding 用于正斜杠 / 字符.

%2F is the percent-encoding for the forward-slash / character.

这个问题与 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.

要恢复到以前的行为:

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆