반응형
각도 UI 라우터: URL이 같은 다른 상태입니까?
내 앱의 랜딩 페이지에는 두 가지 상태가 있습니다.home-public
,home-logged-in
양쪽 상태를 같은 URL로 표시하지만 컨트롤러와 템플릿은 사용자 세션에 의존합니다(사용자가 로그인했는지 여부).
이것을 달성할 수 있는 방법이 있나요?
로드하는 상태를 제어하는 기본 상태를 가질 수 있습니다.또, 그 기본 상태에 URL이 없는 것을 자녀에게 설명하도록 할 수도 있습니다.
.state('home', {
url: "/home",
templateUrl: "....",
controller: function($scope,$state,authSvc) {
if(authSvc.userIsLoggedIn()){
$state.go('home.loggedin')
}else{
$state.go('home.public')
}
}
})
.state('home.public', {
url: "",
templateUrl: "....",
controller: function($scope) {
...........
}
})
.state('home.loggedin', {
url: "",
templateUrl: "....",
controller: function($scope) {
...........
}
})
이것으로 베이스 스테이트의 컨트롤러가 됩니다).home
)사용자가 로그인하고 있는지 아닌지를 확인하고,$state.go()
적절한 상태를 로드합니다.
편집
약속대로, 작업용 플렁크.
두 개의 주가 같은 것을 가질 수 있을지 모르겠다.url
실행 가능한 옵션이 될 수 있는 것은 하나의 상태를 정의하는 것입니다.
$stateProvider.state('home', {
templateUrl: function (stateParams){
// Implement a logic that select what view from the server should be returned for logged in user and otherwise
//return 'templateurl';
}
})
시도해 본 적은 없지만 효과가 있을 겁니다.
언급URL : https://stackoverflow.com/questions/23344055/angular-ui-router-different-states-with-same-url
반응형
'it-source' 카테고리의 다른 글
WooCommerce의 관리 주문 목록에 열 추가 (0) | 2023.04.06 |
---|---|
리스트의 시리얼화>를 JSON으로 합니다. (0) | 2023.04.06 |
Mongodb - "mongo" 데이터베이스와 "mongod" 데이터베이스의 차이점 (0) | 2023.04.06 |
DB에서 실제 연락처 양식 7 구조를 찾는 방법은 무엇입니까? (0) | 2023.04.06 |
호스트: localhost.증명서의 alt name에 없습니다. (0) | 2023.04.06 |