Angular UI Router: Different states with same URL?

The landing page of my app has two states: home-publichome-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.

最新文章

  1. Objective-C歌词解析
  2. iOS中通讯录的开发
  3. ARCGIS进行地理配准并加载到谷歌地球中查看
  4. asp.net mvc中在使用async的时候HttpContext为null的问题
  5. 线段树(区间操作) POJ 3325 Help with Intervals
  6. android.hardware.Camera类及其标准接口介绍
  7. 利用window.name+iframe跨域获取数据详解
  8. Animator组件关闭再打开后参数丢失问题
  9. [ionic开源项目教程] - 第7讲 实现下拉刷新上拉加载ion-refresher和ion-infinite-scroll
  10. JAVA:三种集合LIST、SET、MAP
  11. POJ 1519 Digital Roots
  12. nodejs显现events.js:72抛出错误
  13. HDU 6185 Covering 矩阵快速幂
  14. [转载] FreeMarker教程
  15. centos 编译安装net-snmp 5.6.2
  16. 22.QT-QXmlStreamReader解析,QXmlStreamWriter写入
  17. 学习笔记——xml的入门及解析
  18. 这里有一篇简单易懂的webSocket 快到碗里来~
  19. netty源码解解析(4.0)-8 ChannelPipeline的设计
  20. Django:模型model和数据库mysql(二)

热门文章

  1. js基础盲点
  2. webpac入门
  3. OJB
  4. Day3 CSS 引入及基本选择器
  5. JAVA——不简单的fianl关键字
  6. jQuery 首页搜索区域模块随页面滑动而变化
  7. for in,Object.keys()与for of的用法与区别
  8. python链家网高并发异步爬虫and异步存入数据
  9. python爬虫入门01:教你在 Chrome 浏览器轻松抓包
  10. python 网络编程基础