Angular ngRoute突然将URL转换为编码字符#!/#%2F [英] Angular ngRoute suddenly converts URL into encoded characters #!/#%2F

查看:88
本文介绍了Angular ngRoute突然将URL转换为编码字符#!/#%2F的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中的所有内容都正常工作,直到我尝试添加ngAnimate,ngMaterial和ng-image-gallery。
我不知道添加这些模块是否是问题的根源,但在问题发生之前我没有改变任何其他内容。

Everything in my app was working fine until I tried to add ngAnimate, ngMaterial and ng-image-gallery. I don't know whether adding these modules is the source of the problem, but I didn't change anything else before the problem occurred.

从那时起(即使在我从app.js和index.html中删除了依赖项之后),所有网址都会转换为编码字符...

Since then (even after I removed the dependencies from app.js and index.html) all URLs are converted to encoded characters...

之前看起来像:

http://.../app/index.html#/workshops

不是它转换为:

http://.../app/index.html#!/#%2Fworkshops

当然没有找到任何内容。导航无效,没有任何反应。

and of course nothing is found. The navigation is not working, nothing happens.

为什么现在编码的URL到底了?!即使只是运行index.html,网络服务器也会给我以下网址:

Why the hell is the URL encoded now?! Even just running index.html n the webserver gives me the following URL:

 http://.../app/index.html#!/

有没有人有同样的问题?为什么会那样?更重要的是:我该如何解决这个问题?!非常感谢提前。

我的路线配置:

    'use strict';

    angular.module('myApp').config(['$locationProvider', '$routeProvider',
    function($locationProvider, $routeProvider) {

    $routeProvider
    .when('/', {
        templateUrl : 'modules/start/views/start.html',
        controller: 'StartController'
    })  

    .when('/galerie', {
        templateUrl : 'modules/galerie/views/galerie.html',
        controller: 'GalerieController'
    })
    .when('/kontakt', {
        templateUrl : 'modules/kontakt/views/kontakt.html',
        controller: 'KontaktController'
    })
    .when('/workshops', {
        templateUrl : 'modules/workshops/views/workshops.html',
        controller: 'WorkshopsController'
    })  
    ;
    }]);

这里我如何在导航中切换路线:

ANd here how I switch the routes in navigation:

                <div class="navbar navbar-top hidden-xs">
                    <ul class="nav navbar-nav">
                        <li>
                            <a href='#/'>Start</a>
                        </li>                       
                        <li>
                            <a href='#/workshops'>Workshops</a>
                        </li>
                        <li>
                            <a href='#/galerie'>Galerie</a>
                        </li>
                        <li>
                            <a href='#/kontakt'>Kontakt & Buchung</a>
                        </li>
                    </ul>
                </div>

这是脚本的包含方式:

     <script src="bower_components/angular/angular.js"></script>
     <script src="bower_components/angular-route/angular-route.js"></script>
     <script src="https://use.fontawesome.com/936815fb51.js"></script>
     <script src="app.js"></script>     
     <script src="modules/config/routes.js"></script>
     <script src="modules/start/start.js"></script>
     <script src="modules/start/controllers/StartController.js"></script>
     ...

加法
控制台什么也没说。没问题,没有错误。

Addition The console says nothing. No problems, no errors.

推荐答案

天哪,我刚刚找到答案......间接地,它与添加依赖关系有关,因为我将使用的角度版本从1.58更改为1.61 - 我只是读到哈希前缀更改为'!'。

Gosh, I just found the answer... indirectly, it had to do with adding dependencies, because I changed the used angular version from 1.58 to 1.61 - I just read that the hash prefix changed to '!'.

回答问题的链接在这里:
Angular Route - URL中的额外#

The Link to the answering question is here: Angular Route - Extra # in URL

路由配置中的下一行使路由器像以前一样工作:

The folowing line in the route config makes the router work like before:

$locationProvider.hashPrefix('');

感谢Arjan Einbu在链接中回答了这个问题。这节省了我的一天。

Thanks to Arjan Einbu for answering that question in the link. That saved my day.

这篇关于Angular ngRoute突然将URL转换为编码字符#!/#%2F的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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