解决方式来源: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. nodejs nodejs模块使用及简单的示例

    nodejs模块使用及简单的示例 参考菜鸟教程网:http://www.runoob.com/ 一.fs模块的使用: 1.文件操作: 读文件: //读文件 var fs=require('fs'); ...

  2. ubuntu - 14.04,创建菜单

    我们有的时候可能会把一个执行程序放到一个位置,随后我们希望在ubuntu的菜单里面加入它,这个操作非常简单: 我在Gnome桌面里,选择:“系统工具”->“首选项”->"主菜单& ...

  3. Windows server iis部署Django详细操作

    教程基于Windows server2012+Python3.6+IIS之上部署django的,同样适用于server2012之上的版本服务器和windows7以上的windows操作系统. 文章来自 ...

  4. ThreadLocalRandom原理

    原文链接:https://www.jianshu.com/p/9c2198586f9b 2.2. 并发包中ThreadLocalRandom类原理剖析 ThreadLocalRandom类是JDK7在 ...

  5. 11、OpenCV Python 图像金字塔

    __author__ = "WSX" import cv2 as cv import numpy as np # 高斯金字塔 #金字塔 原理 ==> 高斯模糊+ 降采样 #金 ...

  6. sklearn.metrics.roc_curve使用说明

    roc曲线是机器学习中十分重要的一种学习器评估准则,在sklearn中有完整的实现,api函数为sklearn.metrics.roc_curve(params)函数. 官方接口说明:http://s ...

  7. Sharepoint 页面超链接地址打开

    SharePoint页面: http://test:81/pages/nihao.aspx 页面超链接:<a href="www.baidu.com" >百度</ ...

  8. 在IntelliJ IDEA中配置Google Java Code Style及代码格式化快捷键

    google-java-format plugin should intercept the “Reformat Code” action in IDEA (Ctrl+Alt+L) and apply ...

  9. tp5分组查询

    $data=DB::name('goods_common')->alias('a')->join('all580_goods_attractions w','a.common_id = w ...

  10. 匿名类与lambda区别

    第一种是继承Thread, 重写了Thread.run()    getClass()返回的是匿名类 java.long.Thread$1 第二种是lambda, 重写了Runnable.run()  ...