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. jQuery提供的小方法

    jQuery提供的小方法: 1.选择器 + 事件 + 函数 = 复杂的交互 2.循环处理与选择器匹配的各个元素:each() $("#").each(function(){     ...

  2. php 删除语句

    if($query&&mysql_affected_rows())echo('数据已被删除');else echo('错误,无法删除'); 通过返回影响的行数 来判断是否已经删除

  3. mysql备份,还原命令

    mysql导出数据1.导出整个数据库mysqldump -u用户名 -p 数据库名 >备份文件2.导出一个表mysqldump -u用户名 -p databaseName tablename & ...

  4. 最常见的HTTP错误

    1. HTTP 500错误(内部服务器错误)对对HTTP 500错误的定义已经充分证明了这是一个最常见的HTTP错误. 一般来说,HTTP 500 错误就是web服务器发生内部错误时返回的信息. 例如 ...

  5. adb找不到设备

    提示信息如下所示: adb server is out of date.killing... adb server didn't ACK *failed to start daemon * error ...

  6. iOS:使用导航栏

    要求使用ARC // // main.m // Hello // // Created by lishujun on 14-8-28. // Copyright (c) 2014年 lishujun. ...

  7. BZOI 1507 [NOI2003] Editor

    Background After trying to solve problem EDIT1(Editor) and being ****ed by Brainf**k, Blue Mary deci ...

  8. bzoj 1191: [HNOI2006]超级英雄Hero 并查集 || 匈牙利算法

    1191: [HNOI2006]超级英雄Hero Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1804  Solved: 850[Submit][S ...

  9. C++ Virtual详解(注意函数被隐藏的问题)

    Virtual是C++ OO机制中很重要的一个关键字.只要是学过C++的人都知道在类Base中加了Virtual关键字的函数就是虚拟函数(例如函数print),于是在Base的派生类Derived中就 ...

  10. 利用ROWID 快速更新单表记录

    -----对于普通表 实现: UPDATE T_PM_DEPOSIT_HIS b SET flag = SUBSTR( flag, 1, 8 )||'4'|| CASE WHEN term <= ...