【问题标题】:How can I fix the angular.js routing in my app?如何修复我的应用程序中的 angular.js 路由?
【发布时间】:2014-12-16 00:25:05
【问题描述】:

我正在编写一个基于移动平台类固醇、angular.js 和 firebase.js 的应用程序。最近遇到这样的问题:页面没有加载,因为它试图访问一个奇怪的urlfile://file:///Users/patutinskijfedor/Desktop/firebase/WILLY/www/

Error: Failed to execute 'replaceState' on 'History': A history state object with URL 'file://file:///Users/patutinskijfedor/Desktop/firebase/WILLY/www/' cannot be created in a document with origin 'null'.

我在 Internet 上阅读了有关此问题的信息,并意识到我的问题在于角度路由。它看起来像这样(文件app.js):

angular.module('SCBI', ['SCBI.controllers','ngRoute']).config(function($routeProvider, $locationProvider){
    $locationProvider.html5Mode(true);

    $routeProvider.when('/teachers',{ templateUrl: 'teachers.html'});
    $routeProvider.when('/teachers/:id', {templateUrl: 't.html', controller: 'TeachersListController'});
    $routeProvider.when('/', {templateUrl: 'authorization.html', controller: 'AuthorizationController'});
    $routeProvider.otherwise({redirectTo:'/'});
});

所以问题可能出在html5Mode。我的问题是:如何修复app.js 中的路由?该项目的完整代码在这里:https://github.com/patut/SCBI

【问题讨论】:

  • 会不会是这个file://file:///造成的?不应该只是file:// 或更好的locahost ...
  • 您是使用 Node 来托管它还是只是在文件系统之外运行该站点?
  • 看起来与stackoverflow.com/questions/15105910/…类似的问题
  • 能否尝试在 templateUrls 中添加 '/',例如 /teachers.html 等?

标签: angularjs html url-routing angular-routing ngroute


【解决方案1】:

如果您的 HTML5 页面中提到的基本 URL 不正确,则可能会发生这种情况。 请在此处分享您的基本 URL 标记。

【讨论】:

    猜你喜欢
    • 2013-05-20
    • 1970-01-01
    • 2012-06-16
    • 2017-10-31
    • 1970-01-01
    • 2016-09-09
    • 2020-11-11
    • 2017-12-10
    • 2022-11-06
    相关资源
    最近更新 更多