the below Url shows the books listing of a user under a tenant xxtenant in the following url
http://localhost:5306/xxtenant#/mybooks
the route configuration for the above is below,
$routeProvider.when('/mybooks', {
templateUrl: '/partials/mybooks.html',
controller: 'mybooksCtrl',
resolve: {
//code to check tokens
}
})
the listing page i have one button to edit the book details, if i click the button the browser will redirect to http://localhost:5306/xxtenant#/editbook/7190/edit/saved
$routeProvider.when('/editbook/:bookId?/:action/:status', {
templateUrl: '/partials/editbook.html', controller: 'editbookCtrl', resolve: {
//code to check tokens
}
})
If i click browser back button from this edit page, it is redirecting to the previous page and the url became like below, http://localhost:5306/xxtenant#/mybooks#%2Fmybooks.
So if click edit button, it is redirecting to the edit page and the url will be http://localhost:5306/xxtenant#/editbook/7190/edit/saved#%2Fmybooks
and from there i'm clicking browser back button will redirect to http://localhost:5306/xxtenant#/accessdenied#%2Fmybooks%23%252Fmybooks and since i have specified the route like .otherwise({ redirectTo: '/accessdenied' })
Anyone can please help me why the '/mybooks'
is getting added to the url while clicking back button?
AngularJS Version 1.4.8 and Angular-Route Version 1.4.3
Hi Editing the post since, i found the reason to happen this,
The issue is happening because I'm calling $location.path('/mybooks');
if any changes on the edit book page I'll prevent the back or $locationchangestartevent
and show a popup to save or cancel the changes. On the save or cancel, I'll call the location url the user tried to go. below is my code,
function init() {
onRouteChangeOff = $scope.$on('$locationChangeStart', routeChange);
}
function routeChange(event, newUrl, oldUrl) {
var form = $scope.createbookForm;
if (form.$dirty || $scope.MediaSelected || $scope.ImageSelected || $scope.TrainingTypeSelected) {
var modalInstance = $uibModal.open({
animation: $scope.animationsEnabled,
templateUrl: '/scripts/angular/src/modal.html',
controller: 'ModalInstanceCtrl',
size: 'sm',
resolve: {
modalOptions: function () {
return $scope.modalOptions;
}
}
});
}
modalInstance.result.then(function (returnVal) {
if (returnVal) {
if ($scope.isValidForSavePopUp) {
$scope.saveClass(form);
}
onRouteChangeOff();
$location.path($location.url(newUrl).hash());//here the issue
}
});
event.preventDefault();
return;
}
While calling the $location.path($location.url(newUrl).hash());
its redirecting properly but adding %2f and the value of $location.url(newUrl).hash()
It is working properly if i use $window.location.href = newUrl;
Please advice