私はAngularを初めて使用します。現在、すべてのルートを設定して、希望どおりに機能させようとしています。
セットアップ:
ユーザーが特定のページ(/settings
この例の場合)に移動すると、アプリはユーザーが既にログインしているかどうかを確認する必要があります。ログインしている場合は、通常どおり続行します。それ以外の場合、ユーザーはログインページ(/login
)に移動する必要があります。
欲しいもの:
ユーザーが正常にログインした後、最初にアクセスしようとしていたページに移動する必要があります(/settings
)
私の質問: ユーザーがどこに行こうとしていたかを覚える「角度のある方法」はありますか?
関連コード:
app.js
.when('/settings', {
templateUrl: '/views/auth/settings.html',
controller: 'SettingsCtrl',
resolve: {
currentUser: function($q, $location, Auth) {
var deferred = $q.defer();
var noUser = function() {
//remember where the user was trying to go
$location.path("/login")
};
Auth.checkLogin(function() {
if (Auth.currentUser()) {
deferred.resolve(Auth.currentUser());
} else {
deferred.reject(noUser());
}
});
return deferred.promise;
}
}
})
login.js
$scope.submit = function() {
if(!$scope.logInForm.$invalid) {
Auth.login($scope.login, $scope.password, $scope.remember_me)
//go to the page the user was trying to get to
}
};
これまで私を導いてくれたビデオを提供してくれたJohnLindquistに感謝します。