[英]angular redirect with $location path outside the route
I have an index.html page that has a $routeProvider
inside. 我有一个index.html页面,里面有
$routeProvider
。 Whenever I go on a new path inside this page, I check to see if the user is logged in. Something like this: 每当我进入此页面内的新路径时,都会检查用户是否已登录。类似以下内容:
myApp.run(function($rootScope, $location, authService) {
$rootScope.$on("$routeChangeStart", function (event, next, current) {
$rootScope.title = next.$$route.title;
authService.isLogged().then(null, function() {
$location.path('/login');
});
});
});
I have a separate page called login.html. 我有一个单独的页面,名为login.html。 If the user is not logged in, I want a javascript line to redirect him to login.html.
如果用户未登录,我希望JavaScript行将其重定向到login.html。 With this example I copy / pasted , if I have the URL
在此示例中,如果有URL,我将复制/粘贴
localhost/myapp/#/home
it redirects me to 它将我重定向到
localhost/myapp/#/login
but I want it to redirect me to 但我希望它重定向到
localhost/myapp/login
widthout #
. widthout
#
。
You can just use plain js, if your base is allways /myapp
, login
is enough: 您可以只使用纯js,如果您的基地始终是
/myapp
,则login
就足够了:
$window.location.href = 'login'; //If you care about testability
window.location.href = 'login'; //If you don't
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.