Angular没有响应任何路由与ui路由器 – URL只是消失时,我进入
我正在使用NodeJS + Express来为Angular应用程序提供HTML页面。 它加载时似乎工作正常。 没有错误。
问题是那个页面几乎是空白的 – 除了标题。 但是应该去哪里<div ui-view></div>
部分不会显示任何内容。
更糟的是,当我去一个地址,像
http://localhost:7070/admin/#/rounds
浏览器只是改变它
http://localhost:7070/admin/#/
并回到没有显示。
我的angular度应用程序,在index.js
看起来像这样:
一些.run()
和.config()
设置
app.run(['$rootScope', '$state', '$stateParams', function ($rootScope, $state, $stateParams) { // It's very handy to add references to $state and $stateParams to the $rootScope // so that you can access them from any scope within your applications.For example, // <li ng-class="{ active: $state.includes('contacts.list') }"> will set the <li> // to active whenever 'contacts.list' or one of its decendents is active. $rootScope.$state = $state; $rootScope.$stateParams = $stateParams; } ]); app.config(["$locationProvider", function($locationProvider) { //$locationProvider.html5Mode(true); }]);
国家定义:
app.config( ['$stateProvider', '$urlRouterProvider', function ($stateProvider, $urlRouterProvider) { console.log("Is this running at all?"); $urlRouterProvider.otherwise('/'); $stateProvider .state("admin", { abstract: true, url: '/admin', template: '<ui-view />' }) .state("admin.login", { url: '/login', templateUrl: 'login.html', controller: 'userLoginCtrl' }) /* DASHBOARD */ .state("admin.dashboard", { url: "", controller: 'dashboardAppCtrl', templateUrl: "dashboard.html" }) .state("admin.subjects", { url: "/subjects", controller: 'subjectsCtrl', templateUrl: "subjects.html" }) /* ROUNDS */ .state("admin.rounds", { url: "/rounds", controller: 'roundsAppCtrl', templateUrl: "rounds.html", resolve: { gameId: ['$stateParams', function($stateParams){ console.log("gameId "); return $stateParams.gameId; }] } }) .state("admin.round", { url: "/round/:roundId", controller: 'adminRoundCtrl', templateUrl: "adminround.html", resolve:{ gameId: ['$stateParams', function($stateParams){ return $stateParams.gameId; }], roundId: ['$stateParams', function($stateParams){ return $stateParams.roundId; }] }, }); } ]);
有一个工作的笨蛋
答案相对简单
$urlRouterProvider.otherwise('/admin');
而不是这个
http://localhost:7070/admin/#/rounds
我们必须尝试这个
http://localhost:7070/admin/#/admin/rounds
重点是,每个子状态'admin.xxx'
是'admin'
状态的子状态。 这意味着它inheritance了它的url: '/admin'
另外,我们使用
//$locationProvider.html5Mode(true);
所以,starturl很可能是…
EXTEND:正如评论中所讨论的那样,IIS Express与虚拟应用程序/admin
,所以这部分将在url中两次/admin/#/admin...
http://localhost:7070/admin/index.html // ie http://localhost:7070/admin/
作为我们的应用程序的起始url。 任何路由稍后将在#
号之后进行pipe理
http://localhost:7070/admin/#/admin/round/22
在这里检查