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. 使用php发送电子邮件(phpmailer)

    在项目开发过程中,经常会用到通过程序发送电子邮件,例如:注册用户通过邮件激活,通过邮件找回密码,发送报表等.这里介绍几种通过PHP发送电子邮件的 方式(1)通过mail()函数发送邮件(2)使用fso ...

  2. 初级SQL开发汇总指南

    汇总部分内容来自网络(作者  :zhtbs),比较基础的东西,能够了解比较基础的一些东西. Select语句概要 数据库中数据的提取(查询)使用select 语法,主要有以下几点作用 l  提取的数据 ...

  3. 利用servlet做转发,实现js跨域解决同源问题

    做前端开发,避免不了跨域这个问题,跨域具体什么概念,不赘述,博客里太多.简单说下,我们用js发请求,不管post还是get,如果发请求的对象和当前web页面不在同一域名下,浏览器的同源策略会限制发请求 ...

  4. 静态代理VS动态代理

    代理Proxy: Proxy代理模式是一种结构型设计模式,主要解决的问题是:在直接访问对象时带来的问题 代理是一种常用的设计模式,其目的就是为其他对象提供一个代理以控制对某个对象的访问.代理类负责为委 ...

  5. bzoj 3110: [Zjoi2013]K大数查询 树状数组套线段树

    3110: [Zjoi2013]K大数查询 Time Limit: 20 Sec  Memory Limit: 512 MBSubmit: 1384  Solved: 629[Submit][Stat ...

  6. clang: error: invalid deployment target for -stdlib=libc++ (requires iOS 5.0 or later)

    低于5.0版本的不支持设置成 或 在Xcode中做如下配置 静态库工程也要做同样设置

  7. 你真的了解 MySQL 数据库的运行状况吗?

    2015年第三方市场调查机构 Evans 数据公司最近公布的一系列客户调查数据显示,在过去两年里,MySQL 在所有开发者使用的数据库中获得了25%的市场份额,Evans 公司的本次调查显示,数据库的 ...

  8. Qt中事件处理的方法(图文并茂,仔细看看)

    http://blog.csdn.net/qing666888/article/details/14111271 http://blog.csdn.net/qing666888/article/det ...

  9. 遍历、显示ftp下的文件夹和文件信息

    今天做了通过ftp读取ftp根目录下的所有文件夹和文件,嵌套文件夹查询,总共用到了一下代码: 1.FtpFile_Directory package com.hs.dts.web.ftp; impor ...

  10. 【HDOJ】2966 In case of failure

    KD树,这东西其实在ML经常被使用,不过30s的时限还是第一次见. /* 2966 */ #include <iostream> #include <string> #incl ...