I am at the url path http://localhost:3000/u#/
and I click on an href
link to go to http://localhost:3000/u#/76457898/profile
. I need this to happen without sending a request to server.
But that only happens the second time I click on the href
link.
The first time I click on it, I get myself redirected back to http://localhost:3000/u#/76457898
. Only the second time I click on it the page is not redirected and I get only the users.profile
state takes the <div ui-view><div>
.
The http://localhost:3000/u#/
takes me to the same page as http://localhost:3000/u#/76457898
.
HTML
<a href="{{goToUIState('users.profile', user.userId)}}">
<!--stuff-->
</a>
AngularJS with Angular UI Router
.state('users', {
url: '/:userId',
abstract: true,
resolve: {
user: ['$cookies', '$stateParams', '$http', 'localStorageService',
function($cookies, $stateParams, $http, localStorageService) {
var uid = $cookies.uid || localStorageService.get('uid');
return $http.get('/api/users/' + uid).success(function (resp) {
localStorageService.set('uid', uid);
return resp;
})
}
]
},
views: {
'home': {
templateUrl: '/partials/user/index.html',
controller: ['$scope','$state', 'user', '$stateParams', function($scope, $state, user, $stateParams) {
$scope.user = user.data;
//dynamic ui-sref do not work, so creating a function to do that with $state.href()
$scope.goToUIState = function(state, userId) {
return $state.href(state, {userId: userId});
}
$state.go('users.home');
}]
}
}
})
.state('users.home', {
url: '',
templateUrl: '/partials/user/users.home.html',
controller: [$scope', 'user', function($scope, user) {
$scope.user = user.data;
}]
})
.state('users.profile', {
url: '/profile',
templateUrl: '/partials/user/users.profile.html',
controller: ['$scope', '$rootScope', 'user', '$http', 'fileUpload',
function($scope, $rootScope, user, $http, fileUpload) {
$scope.user = user.data;
//stuff
}]
})
Could somebody help me understand the reason behind why do I get the desired second only when I click the href
link second time and how do I resolve this?
I am using NodeJS/ExpressJS on the server side.