angular 的ui.router 定义不同的state 对应相同的url
2024-08-30 09:38:55
Angular UI Router: Different states with same URL?
The landing page of my app has two states: home-public
, home-logged-in
. Now I want to show both states on the same URL, but let the controller and template depend on the user session (is the user logged in or not?).
Is there a way to achieve this?
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
You could have a base state that controls which state to load, and you could simply have the child stated of that base state not have urls:
.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) {
...........
}
})
Now in the controller of your base state (home
) you can check if the user is logged in or not, and use $state.go()
to load an appropriate state.
最新文章
- Objective-C歌词解析
- iOS中通讯录的开发
- ARCGIS进行地理配准并加载到谷歌地球中查看
- asp.net mvc中在使用async的时候HttpContext为null的问题
- 线段树(区间操作) POJ 3325 Help with Intervals
- android.hardware.Camera类及其标准接口介绍
- 利用window.name+iframe跨域获取数据详解
- Animator组件关闭再打开后参数丢失问题
- [ionic开源项目教程] - 第7讲 实现下拉刷新上拉加载ion-refresher和ion-infinite-scroll
- JAVA:三种集合LIST、SET、MAP
- POJ 1519 Digital Roots
- nodejs显现events.js:72抛出错误
- HDU 6185 Covering 矩阵快速幂
- [转载] FreeMarker教程
- centos 编译安装net-snmp 5.6.2
- 22.QT-QXmlStreamReader解析,QXmlStreamWriter写入
- 学习笔记——xml的入门及解析
- 这里有一篇简单易懂的webSocket 快到碗里来~
- netty源码解解析(4.0)-8 ChannelPipeline的设计
- Django:模型model和数据库mysql(二)