我的主控制器中有以下声明(包裹整个身体):
else{
console.log('Forwarding to Login');
$state.go('signin', {});
console.log($state.$current);
}
它实际被调用,但没有任何反应,当前状态为空。
现在有趣的部分:我只是在本地设置nginx并将默认配置文件的根路径指向我项目的根文件夹..一切正常。
那么什么可能导致ExpressJS在使用$ state.go时不重定向和加载控制器?使用ui-sref工作......
这是我的express.js配置:
var express = require('express'); var app = express();
app.use('/libs', express.static(__dirname + '/libs')); app.use('/assets', express.static(__dirname + '/assets')); app.use('/app', express.static(__dirname + '/app')); //app.use(express.errorHandler());
app.set('port', process.env.PORT || 3000);
app.all('/*', function(req, res, next) {
// Just send the index.html for other files to support HTML5Mode
res.sendFile('index.html', { root: __dirname }); });
/** * Start Server */
var server = app.listen(3000, function () {
var host = server.address().address; var port = server.address().port;
console.log('X is listening at http://%s:%s', host, port);
});
以下是我的州
$stateProvider
// Dashboard
.state('dashboard', {
url: "/dashboard",
templateUrl: "/app/components/dashboard/dashboard.view.html",
data: {pageTitle: 'Home', pageSubTitle: 'MyTitle Workspace'},
resolve: {
deps: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'MyApp',
insertBefore: '#ng_load_plugins_before',
files: [
]
});
}]
}
})
// Login
.state('signin', {
url: '/signin',
templateUrl: '/app/components/login/login.view.html',
data: {pageTitle: 'Sign in', pageSubTitle: ''},
controller: 'LoginController',
controllerAs: 'loginCtrl',
resolve: {
deps: ['$ocLazyLoad', function ($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'MyApp',
insertBefore: '#ng_load_plugins_before',
files: [
'/app/shared/authentication/login.controller.js'
]
});
}]
}
})
我真的很感激任何帮助:)
最佳, 帕特里克
答案 0 :(得分:0)
如果不知道您的路线是什么样的,我建议您将以下内容添加到.run:
app.run(function ($rootScope, $state) {
$rootScope.$on('$stateChangeStart', function (event, next) {
/* Fired prior to any route change */
});
$rootScope.$on('$stateChangeSuccess', function (event, toState, toParams, fromState, fromParams) {
/* this will fire on EVERY successful route change */
});
/*
Logs to console if a route change fails for any reason
*/
$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
console.log('state change error - ' + error + ' - to: ' + angular.toJson(toState) + ' params: ' + angular.toJson(toParams) + '\nfrom: ' + angular.toJson(fromState) + ' params: ' + angular.toJson(fromParams));
});
});
这至少可以让您了解正在发生的事情。您甚至可以直接在这些块中处理问题