我正在为我的应用使用角度js。
在这里,My Angular代码为:
var app = angular.module('TaskManager', ['ngCookies']);
app.controller('LoginController', function($scope, $http, $location, $cookieStore) {
$scope.login = function(str) {
console.log(".......... login called......");
$http({
method: 'POST',
url: '../TaskManager/public/user/login',
data: $.param({
email: email.value,
password: password.value
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.success(function(data, status) {
console.log(data);
var result = data.response;
console.log(result);
if (result == "success") {
//storing value at cookieStore
$cookieStore.put("loggedin", "true");
$cookieStore.put("loggedUserId", data.user_id);
$cookieStore.put("password", data.password);
$cookieStore.put("type", data.type);
$cookieStore.put("email", data.email);
location.href='Dashboard.html';
} else alert(data.message);
});
});
app.controller('DashboardController', function($scope, $http, $location, $cookieStore) {
$scope.users = [];
$http({
method: 'POST',
url: '../TaskManager/public/task/tasklist',
data: $.param({
logged_userid: userId,
password: password,
status: 'All',
user_id: useridToFetch
}),
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
})
.success(function(data, status) {
console.log(data);
$scope.users = data.users;
});
//location.hash="";
console.log(window.location);
});
它工作正常,但在登录后重定向到仪表板页面时,location.hash
正在分配#/PAGE_NAME
。它变为location.hash=#/PAGE_NAME
,导致URL值重复。
像:
http://localhost:8085/NovaTaskManager/Dashboard.html#/Dashboard.html
我试图在DashboardController上清除哈希值,这会清除一段时间但刷新页面后会再次显示早期的URL。
不知道:
1. why location.hash is getting assigned by default ?
2. How it can be resolved ?
任何建议都将不胜感激。