解决方式来源: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. Vue 组件 生命周期函数mounted

    生命周期函数mounted:页面刷新触发mounted(){ console.log('我在页面刷新时触发');} Tips:使用export default function Add(){},与ex ...

  2. C#中如何防止Excel做科学计算法转换

    C#中如何防止Excel做科学计算法转换  string style = @"<style>.text{mso-number-format:\@;}</style>& ...

  3. t-sql read xlsx

    How to Read and Load an Excel 2007 or Excel 2010 File Without Using Import/Export Utility To read an ...

  4. javascript拖拽事件

    <!DOCTYPE html> <html> <head> <title></title> <style type="tex ...

  5. x0vncserver

    x0vncserver -display :0 -passwordfile ~/.vnc/passwd

  6. paramiko模块的安装和使用(含上传本地文件或文件夹到服务器,以及下载服务器文件到本地)

    安装和使用分两步介绍: 介绍一下,本文的运行环境是win7 64位 和python 2.7  . 安装: WIN7_64位 安装python-ssh访问模块(paramiko)的安装教程,本人亲测下面 ...

  7. 实施MySQL ReplicationDriver支持读写分离

    MySQL 提供支持读写分离的驱动类: com.mysql.jdbc.ReplicationDriver 替代 com.mysql.jdbc.Driver 注意,所有参数主从统一: jdbc:mysq ...

  8. Margarite and the best present

    Little girl Margarita is a big fan of competitive programming. She especially loves problems about a ...

  9. P2905 [USACO08OPEN]农场危机Crisis on the Farm

    传送门 DP 设 f [ i ] [ j ] [ k ] 表示已经走了 i 步,向上走了 j 步,向右走了 k 步时能拯救的最多奶牛数(j,k可以为负,表示反向) 设 g [ i ] [ j ] 表示 ...

  10. CF D Bicolorings

    题意 给一个2行n列的矩阵填上黑色和白色,求连通块个数为k个的填色方案数量(mod 998244353)   因为只有两行,为n-1列的矩阵增加1列的情况数只有很少,容易想到用 (i,k) 表示 i  ...