URL パスにいるので、リンクをhttp://localhost:3000/u#/
クリックしてに移動します。サーバーにリクエストを送信せずにこれを行う必要があります。しかし、それはリンクを 2 回クリックしたときにのみ発生します。href
http://localhost:3000/u#/76457898/profile
href
初めてクリックすると、 にリダイレクトされhttp://localhost:3000/u#/76457898
ます。2 回目だけクリックすると、ページはリダイレクトされず、users.profile
状態だけが取得され<div ui-view><div>
ます。
はhttp://localhost:3000/u#/
と同じページに移動しhttp://localhost:3000/u#/76457898
ます。
HTML
<a href="{{goToUIState('users.profile', user.userId)}}">
<!--stuff-->
</a>
Angular UI ルーターを使用した AngularJS
.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
}]
})
リンクを2回目にクリックしたときにのみ目的の秒が得られる理由と、href
これを解決するにはどうすればよいかを誰かが理解するのを手伝ってくれますか?
サーバー側で NodeJS/ExpressJS を使用しています。