URL 경로 http://localhost:3000/u#/
에 있으며 http://localhost:3000/u#/76457898/profile
으로 이동하려면 href
링크를 클릭합니다. 서버에 요청을 보내지 않고이 작업이 필요합니다. 하지만 두 번째로 href
링크를 클릭하면됩니다.각도 UI 라우터 및 NodeJS에서 ui-sref를 사용하는 방법
처음 클릭하면 http://localhost:3000/u#/76457898
으로 리디렉션됩니다. 두 번째로 페이지를 클릭 할 때 페이지가 리디렉션되지 않고 users.profile
상태 일 뿐이며 <div ui-view><div>
상태가됩니다.
http://localhost:3000/u#/
은 http://localhost:3000/u#/76457898
과 같은 페이지로 이동합니다. 각도 UI 라우터와
HTML
<a href="{{goToUIState('users.profile', user.userId)}}">
<!--stuff-->
</a>
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
}]
})
누군가 내가 href
링크를 클릭하는 경우에만 제가 원하는 초를 얻을 왜 뒤에 이유를 이해하는 데 도움이 수 두 번째로 어떻게 해결할 수 있습니까?
서버 측에서 NodeJS/ExpressJS를 사용하고 있습니다.
나는 당신의 HTML에 혼란 스럽다. 당신은 다음과 같은 것을 사용해서는 안됩니다. [http://docs.sourceforge.net/] ? '{{ xxx }}' –
@DavidSpence : '{{ xxx }}'을 사용하는 경우에도'http : // localhost : 3000/u #/76457898/profile'을 보려면 두 번 클릭해야합니다. 처음 클릭 할 때'http : // localhost : 3000/u #/76457898'에 도착하고, 두 번째로 클릭하면 마침내 원하는 http : // localhost : 3000/u #/76457898/profile'. – skip
@DavidSpence : 문제는 어떻게 든 동적 바인딩 부분에있는 것처럼 보입니다. https://github.com/angular-ui/ui-router/issues/395. 동적 인 무언가를 바인딩하기 위해 내가했던 것처럼 HTML을 사용해야했습니다. – skip