Let's say we want a parent state which is a abstract state. Two children states, one is for sinlge account view and another is for multi-accounts view.

By default, we want to go single account view:

            .state('selfcare.my-services', {
url: 'my-services',
abstract: true,
resolve: {
authenticate: authenticate
}
})
.state('selfcare.my-services.single', {
url: '',
views: {
'main@': {
template: '<clm-my-services></clm-my-services>'
}
},
resolve: {
router: ($q, UserService) => {
let loginName = UserService.userProfileDataFromJWT.loginName;
return UserService.getServiceDetails(loginName)
.then((res) => {
if (_.size(res.billAccounts) > 1) {
return $q.reject('TO_MULTI_SERVICES');
} else {
return $q.when();
}
});
}
}
})

The idea is:

  • Keep the default child state's url empty, so it knows this child state is default one, it will have the same url as parent.
  • Make parent state as abstract state.
  • authenticate is only need for parent, because it always goes from parent to children, so if parent is authenticated then it means child state is also authenticated.

Then in the code we have:router resolve block, you can name it anything you want:

router: ($q, UserService) => {
let loginName = UserService.userProfileDataFromJWT.loginName;
return UserService.getServiceDetails(loginName)
.then((res) => {
if (_.size(res.billAccounts) > 1) {
return $q.reject('TO_MULTI_SERVICES');
} else {
return $q.when();
}
});

It says that if there is multi service accounts then go multi-service account. So reject the promise, it will be handled by $stateChangeError.

$stateChangeError:

$rootScope.$on('$stateChangeError', function (event, toState, toParams, fromState, fromParams, error) {
switch (error) {case 'TO_SINGLE_SERVICE':
return $state.go('selfcare.my-services.single');
case 'TO_MULTI_SERVICES':
return $state.go('selfcare.my-services.compsite');
default:
$state.go('login.main');
} $('.progress-bar')
.hide();
});

The same as to handle multi-account view. And because you cannot access abstract directly by url, so to access the account, you need to do:

ui-sref="selfcare.my-services.single"

[AngularJS] Default Child state and nav between child state的更多相关文章

  1. Unable to make the session state request to the session state server处理

    Server Error in '/' Application. Unable to make the session state request to the session state serve ...

  2. 在IIS上发布项目后浏览时报的错:Unable to make the session state request to the session state server

    错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...

  3. Unable to make the session state request to the session state server处理方法

    Server Error in '/' Application. Unable to make the session state request to the session state serve ...

  4. 关于props和state以及redux中的state

    React的数据模型分为共有数据和私有数据,共有数据可以在组件间进行传递,私有数据为当前组件私有.共有数据在React中使用props对象来调用,它包含标签所有的属性名称和属性值,props对象有三个 ...

  5. Ext.state.Manager.setProvider(new Ext.state.CookieProvider())

    Ext.state.Manager.setProvider(new Ext.state.CookieProvider()) 初始化Ext状态管理器,在Cookie中记录用户的操作状态,如果不启用,象刷 ...

  6. 转: 解决【Unable to make the session state request to the session state server】

    错误描述: Unable to make the session state request to the session state server. Please ensure that the A ...

  7. File(File f, String child) File(String parent, String child)

    (转载)File(File f, String child) 根据f 抽象路径名和 child 路径名字符串创建一个新 File 实例. f抽象路径名用于表示目录,child 路径名字符串用于表示目录 ...

  8. [Functional Programming + React] Provide a reasonable default value for mapStateToProps in case initial state is undefined

    For example we have a component, it needs to call 'react-redux' connect function. import { compose, ...

  9. Part 28 AngularJS default route

    At the moment the problem is that, if you try to navigate to a route that is not configured, you wil ...

随机推荐

  1. compser 执行命令提示do not run composer as root/super !

    这个是因为composer为了防止非法脚本在root下执行,解决办法随便切换到非root用户即可

  2. mysql慢速查询

    linux下配置慢查询: 修改my.cnf文件,在[mysqld]模块下添加 #slow_query_log=1 有些人说这个是slow_query的开关,但是我加上以后提示错误.log_slow_q ...

  3. ListView item 中TextView 如何获取长按事件

    昨天晚上小伙伴突然来信, ListView item中嵌套的TextView 无法获取长按事件 从前从来没有仔细留意过, coding后发现...果然没什么动静 而且没有合适的API让我调用获取Tex ...

  4. 【python】只执行普通除法:添加 from __future__ import division

    from __future__ import division 注意future前后是两个下划线

  5. theano中的concolutional_mlp.py学习

    (1) evaluate _lenet5中的导入数据部分 # 导入数据集,该函数定义在logistic_sgd中,返回的是一个list datasets = load_data(dataset) # ...

  6. AndroidStudio 更新gradle Error:Failed to complete Gradle execution. Cause: Connection reset

      Android Studio 报错:Error:Failed to complete Gradle execution.  Cause: Connection reset.把最新可以运行的项目中g ...

  7. 【HDU3530】 [Sdoi2014]数数 (AC自动机+数位DP)

    3530: [Sdoi2014]数数 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 682  Solved: 364 Description 我们称一 ...

  8. C语言嵌入式系统编程修炼之三:内存操作

    数据指针 在嵌入式系统的编程中,常常要求在特定的内存单元读写内容,汇编有对应的MOV指令,而除C/C++以外的其它编程语言基本没有直接访问绝对地址的能力.在嵌入式系统的实际调试中,多借助C语言指针所具 ...

  9. restful风格,restcontroller与controller

    restful风格,restcontroller与controller 初步接触springmvc的时候,被要求使用restful风格,彼时一头雾水,不懂何谓restful,参阅了很多资料,慢慢的接触 ...

  10. GPL,LGPL和BSD等协议注意事项

    使用开源软件必须注意GPL,LGPL和BSD等协议 简而言之,GPL协议就是一个开放源代码协议,软件的初始开发者使用了GPL协议并公开软件的源程序后,后续使用该软件源程序开发软件者亦应当根据GPL协议 ...