【问题标题】:AngularJS Router app freezes webpageAngularJS路由器应用程序冻结网页
【发布时间】:2018-04-18 14:37:47
【问题描述】:

首先,我能够通过更新 CDN 链接来修复空白页面。它能够加载 header.html 和 footer.html 而没有任何错误消息,但在尝试显示视图页面时它会冻结。我不确定它是否与app.js 或CDN https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js 链接有关?

没有 JS 控制台错误。

app.js

var myApp= angular.module("myApp", ["ngRoute"]);

myApp.config(function ($routeProvider, $locationProvider) {
$locationProvider.hashPrefix('');
$routeProvider
    .when('/', {
    templateUrl: 'index.html'
})
    .when('/about', {
    templateUrl: 'views/about.html'
})
    .when('/contact', {
    templateUrl: 'views/contact.html'
})
    .when('/business', {
    templateUrl: 'views/business-interpreting.html'
})
    .when('/deafconsumers', {
    templateUrl: 'views/deaf-consumers.html'
})
    .when('/educational', {
    templateUrl: 'views/educational-interpreting.html'
})
    .when('/recruitment', {
    templateUrl: 'views/interpreter-recruitment.html'
})
    .when('/legal', {
    templateUrl: 'views/legal-interpreting.html'
})
    .when('/medical', {
    templateUrl: 'views/medical-interpreting.html'
})
    .when('/newclient', {
    templateUrl: 'views/new-client.html'
})
    .when('/request', {
    templateUrl: 'views/request-interpreter.html'
})
    .when('/vri', {
    templateUrl: 'views/video-remote-interpreting.html'
});
});

链接

<div class="nav">
    <ul>
        <li><a href="#!request">REQUEST AN INTERPRETER</a></li>
        <li><a href="#!newclient" class="arrow">HEARING/NEW INFO</a>
            <span>
            <a href="#!medical">MEDICAL INTERPRETING</a>
            <a href="#!legal">LEGAL INTERPRETING</a>
            <a href="#!business">BUSINESS INTERPRETING</a>
            <a href="#!educational">EDUCATIONAL INTERPRETING</a>
            <a href="#!vri">VRI</a>
            </span>
        </li>
        <li><a href="#!consumers">DEAF CONSUMERS</a></li>
        <li><a href="#!recruitment">INTERPRETER RECRUITMENT</a></li>
        <li><a href="#!about">ABOUT</a></li>
    </ul>
</div>

模块

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular-route.js"></script>

HTML

<!-- Header section -->
<div ng-include="'views/header.html'"></div> <--- loads just fine, but froze.

<!-- Views section -->
<div ng-view></div>  <---------- it froze the webpage

<!-- Footer section -->
<div ng-include="'views/footer.html'"></div> <--- loads just fine, but froze.

【问题讨论】:

  • 控制台有错误吗?
  • 我该怎么做?
  • 打开浏览器的控制台。在键盘上按 F12
  • 你的模块代码在哪里?
  • 我在 app.js 第 5 行显示 Uncaught SyntaxError: Unexpected token.

标签: javascript angularjs angular-ui-router


【解决方案1】:

尝试像这样配置$locationProvider

app.config(function($locationProvider) {

    $locationProvider.hashPrefix('');
    $locationProvider.html5Mode({
    enabled: false,
    requireBase: true
  });
});

我的链接 哪个给:http://blablabla.co:8888/blabla#/mylink/

希望对您有所帮助。

【讨论】:

  • 我的链接只是一个例子....试试$locationProvider的配置
  • 我做了,但仍然是空白页
  • 尝试在你的 href 链接之前添加 '/#/' 比如 '/#!medical' 并在 locationProvider 配置中启用为 true
  • myApp.config(function ($routeProvider, $locationProvider) { $locationProvider.hashPrefix(''); $locationProvider.html5Mode({ enabled: true, requireBase: true }); - 这是我所做的,更新链接后仍然是空白页面/#!
猜你喜欢
  • 1970-01-01
  • 2019-09-01
  • 2016-04-14
  • 2015-12-08
  • 2014-07-18
  • 1970-01-01
  • 2019-03-05
  • 1970-01-01
  • 2019-11-04
相关资源
最近更新 更多