我有一个使用AngularJS的SPA。我刚刚添加了安全性/身份验证,除了在查询字符串中存在returnUrl
后重定向后,一切似乎都能很好地工作。
我的应用程序中有代码,如果没有用户通过身份验证,它将重定向到我的登录路由。例如,如果用户尝试访问http://localhost:55841/#/group/15
(需要身份验证),则会使用以下URL重定向到登录路由:
http://localhost:55841/#/login?returnUrl=%2Fgroup%2F15
这是我的登录方法,如果成功登录时该方法应该重定向到returnUrl路由:
var login = function (credentials) {
return $http.post(baseUrl + 'api/login', credentials).then(function (response) {
//do stuff
var returnUrl = $location.search().returnUrl;
if (returnUrl) {
$location.path(returnUrl);
//$location.path('/group/15');
}
$location.path('/');
});
};
当我调试login方法时,returnUrl的值为/group/15
,这是我所期望的,但它导航到以下URL:
http://localhost:55841/#/?returnUrl=%2Fgroup%2F15
提前致谢
答案 0 :(得分:2)
<?php
/*
Plugin Name: Plugin Display
Plugin URI: http://test.com
Description: Plugin for displaying info
Author: rohail
Version: 1.0
Author URI: http://test.com
*/
add_action('wp', 'prefix_setup_schedule');
/**
* On an early action hook, check if the hook is scheduled - if not, schedule it.
*/
function prefix_setup_schedule() {
if (!wp_next_scheduled('prefix_hourly_event')) {
wp_schedule_event(time(), 'hourly', 'prefix_hourly_event');
}
}
add_action('prefix_hourly_event', 'prefix_do_this_hourly');
/**
* On the scheduled action hook, run a function.
*/
function prefix_do_this_hourly() {
echo "test test";
}
?>
提示:您需要在“returnUrl”中过滤大量的URL。考虑最后一页为var login = function (credentials) {
return $http.post(baseUrl + 'api/login', credentials).then(function (response) {
$rootScope.currentUser = response.data;
$rootScope.$broadcast('currentUser', response.data);
var returnUrl = $location.search().returnUrl;
if (returnUrl) {
console.log('Redirect to:' + returnUrl);
$location.path(decodeURI(returnUrl)); // <- executed first, but not redirect directly.
//$location.path('/group/15');
} else { //else :)
console.log('Redirect returnUrl not found. Directing to "/".');
$location.path('/'); // <- only redirect if no returnUrl isset/true
}
}, function (response) {
$rootScope.currentUser = null;
$rootScope.$broadcast('currentUser', null);
return $q.reject(response);
});
};
的情况。所以它是一个无限循环。