我是 angularjs 的新手,我正在尝试使用这个 generator-angular-fullstack,
我想要页面登录而不是主页面,我使用代码,我的解决方案是在 MainCtrl 中添加'authenticate:true'
angular.module('myapp')
.config(function ($stateProvider) {
$stateProvider
.state('main', {
url: '/',
templateUrl: 'app/main/main.html',
controller: 'MainCtrl',
authenticate: true
});
});
并注释“event.preventDefault();”行 在 app.js 中的 run 函数中
.run(function ($rootScope, $location, Auth) {
// Redirect to login if route requires auth and you're not logged in
$rootScope.$on('$stateChangeStart', function (event, next) {
Auth.isLoggedInAsync(function(loggedIn) {
if (next.authenticate && !loggedIn) {
//event.preventDefault();
$location.path('/login');
}
});
});
但我不确定这种变化是好的还是有其他最佳解决方案。