解决方式来源:https://stackoverflow.com/questions/25316591/angularjs-ui-router-state-reload-child-state-only/25322797#25322797

路由路径设置:structured.text   ;structured是第一层路由,text是第二层路由;

问题如下,当$state.transitionTo路由到第二层是,structured的controller也会执行一次,导致页面控件重新加载刷新。

$state.transitionTo(
"structured.text",
{ args : $stateParams },
{ reload: false}
);

查了github看到 https://github.com/angular-ui/ui-router/issues/1612,说此问题已经被fixed,然而设置了reload: stateObj并没有卵用。

I think this makes sense and is a good idea. I'd like to omit the second reloadState parameter, and overload the existing reload parameter.

  • { reload: true }// reloads all,
  • { reload: 'foo.bar' } // reloads top.bar, and any children
  • { reload: stateObj } // reloads state found in stateObj, and any children

Squash your commits and set your commit message to match the contributor guidelines. If @nateabeleconcurs, I think we'll merge this in.

直到看到了https://stackoverflow.com/questions/21105528/difference-between-state-transitionto-and-state-go-in-angular-ui-router

$state.go(to [, toParams] [, options])

Returns a Promise representing the state of the transition.

Convenience method for transitioning to a new state. $state.go calls $state.transitionTointernally but automatically sets options to { location: true, inherit: true, relative: $state.$current, notify: true }. This allows you to easily use an absolute or relative to path and specify only the parameters you'd like to update (while letting unspecified parameters inherit from the current state).


$state.transitionTo(to, toParams [, options])

Returns a Promise representing the state of the transition.

Low-level method for transitioning to a new state. $state.go() uses transitionTo internally. $state.go() is recommended in most situations.

$state.transitionTo是底层方法,用$state.go是用它实现的,$state.go设置了一些默认参数 ,于是用$state.go试了下,竟然成功;

debug看了下原来是默认options inherit:true和reload:false共同引发的问题:

错误写法1:

$state.transitionTo(
"structured.text",
{ args : $stateParams },
{ reload: true}
);

 原因:路由写了两级,structured的controller会被重复执行

错误写法2:

$state.transitionTo(
".text",
{ args : $stateParams },
{ reload: true}
);

 原因:relative没有设置和inherit默认又是false,报错路由找不到

正确写法:

$state.go(
'structured.text',
  {},
  { reload: 'structured.text'}
);

https://github.com/angular-ui/ui-router/issues/1612#issuecomment-77757224 这里作为一个bug被fixed,路由设计还是太蠢...

推荐使用$state.go, 用$state.transitionTo底层方法的话,options要都正确,问题解决,搞了半天研究这个破东西,api设计的让人郁闷。

Angularjs ui router,路由嵌套 父controller执行问题的更多相关文章

  1. [转]AngularJS+UI Router(1) 多步表单

    本文转自:https://www.zybuluo.com/dreamapplehappy/note/54448 多步表单的实现   在线demo演示地址https://rawgit.com/dream ...

  2. angularJS ui router 多视图单独刷新问题

    场景:视图层级如下 view1 --view11 --view111 需求:view11的一个动作过后,单独刷新view12 解决方式:修改层级设计 view1 --view11 --view111 ...

  3. angular ui.router 路由传参数

    angular已经用了一段时间了,最近在做路由,做一下笔记. 路由跳转的时候进行穿参 ui.router方式 <a ui-sref="edit({id:5})"> 编辑 ...

  4. angularjs中的路由介绍详解 ui-route(转)

    http://www.cnblogs.com/littlemonk/p/5500801.html 这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui rou ...

  5. angularjs中的路由介绍详解 ui-route

    这篇文章主要介绍了Angularjs中UI Router全攻略,涉及到angularjs ui router的基本用法,需要的朋友参考下吧   首先给大家介绍angular-ui-router的基本用 ...

  6. AngularJS 使用 UI Router 实现表单向导

    Today we will be using AngularJS and the great UI Router and the Angular ngAnimate module to create ...

  7. [转]AngularJS 使用 UI Router 实现表单向导

    本文转自:http://www.oschina.net/translate/angularjs-multi-step-form-using-ui-router 今天我们将使用AngularJs和伟大的 ...

  8. [AngularJS] “多重路由”嵌套模块——AngularJS“路由”嵌套学习资料教程

    这是小编的一些学习资料,理论上只是为了自己以后学习需要的,但是还是需要认真对待的 以下内容仅供参考,请慎重使用学习 1.AngularJS路由嵌套 Angularjs本身自带路由模块,可以满足通过不同 ...

  9. angularjs ngRoute和ui.router对比

    ngRoute模块是angularjs自带的路由模块,ui.router是一个第三方路由模块,接下来将对两者进行一个对比: ng-router(angular-router.js) ng-view n ...

随机推荐

  1. 双击获取GridView控件行信息

    有网友要求在GridView控件上,不管是单击(onclick)还是双击(ondblclick),想获取所击行的信息.技术难度是为GridView的行注册单击或是双击事件.看例子吧:在数据库中创建数据 ...

  2. 【转】 robotframework(rf)中对时间操作的datetime库常用关键字

    转自http://blog.csdn.net/r455678/article/details/52993765 DateTime库是robotframework内置的库 1.对固定日期进行操作,增加或 ...

  3. 拖放(Drag和Drop)--html5

    拖放,就是抓取一个对象后拖放到另一个位置.很常用的一个功能,在还没有html5的时候,我们实现这个功能,通常会用大量的js代码,再利用mousemove,mouseup等鼠标事件来实现,总的来说比较麻 ...

  4. HDU - 1166 敌兵布阵 方法一:(线段树+单点修改,区间查询和) 方法二:利用树状数组

    C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况.由于 ...

  5. kuangbin专题16H(next数组)

    题目链接: https://vjudge.net/contest/70325#problem/H 题意: 输入字符串 str, 求 str 子串中既是 str 前缀又是 str 后缀的的字符串长度, ...

  6. 【RMQ】【Sparse_Table算法】

    摘自网友,具体哪个忘记了,抱歉~ 定义: RMQ(Range Minimum/Maximum Query),即区间最值查询,是指这样一个问题: 对于长度为n的数列A,回答若干询问RMQ(A,i,j) ...

  7. kuangbin专题十六 KMP&&扩展KMP HDU2087 剪花布条

    一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案.对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢? Input输入中含有一些数据,分别是成对出现的花布条和小 ...

  8. Java实现几分钟之后调度任务的定时器

    几分钟之后执行某一操作,使用定时器Timer可以实现 Timer是jdk中提供的一个定时器工具,使用的时候会在主线程之外起一个单独的线程执行指定的计划任务,可以指定执行一次或者反复执行多次. 具体实现 ...

  9. 6.动态sql - if

    满足条件的数据 mapper.xml 满足if条件就执行,不满足就不加 <select id="selectStateByTitle" parameterType=" ...

  10. 富文本编辑器...quill 的使用放...

    移动端 quill 时候用的 是 div 而不是 textarea.... 引入 dom <link href="//cdn.quilljs.com/1.3.6/quill.snow. ...