我有一个应用程序使用角度 ui 路由器 with html5模式(真)。当运行和路由到其他状态时,一切似乎都工作正常。
我的默认状态是应用程序/日历这是在 module.run() 期间设置的
但是当我刷新页面而我当前处于其他路线时(可以说应用程序/个人资料)它带我回到应用程序/日历。
调试我注意到刷新页面后 $state.current 始终为空
Object {name: "", url: "^", views: null, abstract: true}
如果只有 $state.current 有值,我就可以转换到当前状态。
我有什么遗漏的吗?
希望有人可以提供帮助。
My 服务器路由好像
app.get('/:var(/|app/calendar|app/customers|app/profile|app/settings)?', function(req, res) {
res.sendFile('/app/main/main.html',{ root: '../Appt/public' });
});
我总是提供同一个文件。
and my 前端状态配置
(
function()
{
angular.module('Appt.Main').config(['$stateProvider','$locationProvider',function($stateProvider,$locationProvider)
{
$locationProvider.html5Mode(true);
var calendar = {
name: 'calendar',
url: 'app/calendar',
controller: 'Appt.Main.CalendarController',
controllerAs: 'calendar',
templateUrl: '/app/main/calendar/calendar.html'
},
customers = {
name: 'customers',
url: 'app/customers',
controller : 'Appt.Main.CustomersController',
controllerAs : 'customers',
templateUrl : '/app/main/customers/customers.html'
},
profile = {
name: 'profile',
url: 'app/profile',
controller : 'Appt.Main.ProfileController',
controllerAs : 'profile',
templateUrl : '/app/main/profile/profile.html'
},
settings = {
name: 'settings',
url: 'app/settings',
controller : 'Appt.Main.SettingsController',
controllerAs : 'settings',
templateUrl : '/app/main/settings/settings.html'
};
$stateProvider.state(calendar);
$stateProvider.state(customers);
$stateProvider.state(profile);
$stateProvider.state(settings);
}]);
}
)();
我的模块.运行
(
function()
{
'use strict';
angular.module('Appt.Main',['ngRoute','ui.router','Appt.Directives'])
.run(['$state','$stateParams', function ($state,$stateParams) {
console.log('Appt.Main is now running')
console.log($state.current);
console.log($stateParams);
$state.transitionTo('calendar');
}])
}
)();