第5篇:ui-router路由带参数跳转后controller执行两次的问题处理
来源:互联网 发布:cctv网络直播电视大全 编辑:程序博客网 时间:2024/05/20 02:23
最近用到了ui-router做项目:
跳转路由:
<a ui-sref="createOffer" class="third-item">Create Offer</a>路由配置:
.state('createOffer', { url: "/offerManager/create/{id}", templateUrl: "./view/appOffer/offer/create/createOffer.html", controller:"createOfferCtrl"})路由跳转:
$state.go("createOffer",{id:getId});
但是当点击跳转时会发现页面对应的子controller执行了两次:
网上查的大部分都是因为controller在html中多写了一次的原因,但是这里的controller并没有第二次配置,几经折腾在github上找到了解决办法:
Let's say you have a state with an optional parameter :.state('app.numbers', { url: '/numbers{timestamp:.*}', templateUrl: 'numbers/templates/app.numbers.html', controller: 'NumberListCtrl'})if you just use a link like this, the controller NumberListCtrl will be loaded twice, once with a timestamp parameter with an undefined value, and once with a '' value :<a ui-sref=".numbers">numbers</a>
也就是说路由跳转了两次,一次是带参数执行的,另一次是为不带参数执行,当然上面也给了解决办法:
To prevent your controller from being loaded twice, you can use the following methods :<a ui-sref=".numbers({timestamp:''})">numbers</a>or use $state in js :$state.go('app.numbers', {timestamp: ''});or add these lines at the top of your controller :// prevent double controller load because of the optional parameterif (typeof $stateParams.timestamp === 'undefined') { return;}
于是将路由改成这样:
<a ui-sref="createOffer({id : ''})" class="third-item">Create Offer</a>再次跳转对应的controller就不会执行两次了。
参考:https://github.com/angular-ui/ui-router/issues/1476
0 0
- 第5篇:ui-router路由带参数跳转后controller执行两次的问题处理
- 第4篇:ui-router 切换路由后页面不回到顶部的解决办法
- 第26篇:AngularJS+ui-router实现一个超简单的登陆和跳转的二级路由demo
- ReactJs Router 路由地址跳转方式带参数
- SpringMvc Controller 带参数的重定向 不能跳转问题处理方案
- ui-router--登录页通过路由跳转到内页的demo
- controller 带参数跳转
- vue.js用vue-router路由传参时页面刷新后参数消失的问题
- 第18篇:ui-router强制刷新当前路由
- angular ui-router 路由默认跳转语句$urlRouterProvider.otherwise(‘路径');与<a>共用时存在的问题
- vue路由带参跳转,刷新后参数不消失
- UI-Router的路由事件
- react入门之路由----react-router的跳转问题
- 第3篇:angularJS使用ui-router的嵌套路由配置
- angular ui.router 路由传参数
- angularJs 中ui-router 路由向controller传递数据
- 关于Spring mvc 一次请求Controller执行两次的问题
- ui-router参数传递问题
- JSP--(一)
- [网易]字符串编码
- 【转】详解ThreadPoolExecutor
- 解决java前后端分离跨域的问题
- pandas选取特定索引的行
- 第5篇:ui-router路由带参数跳转后controller执行两次的问题处理
- java-模拟斗地主的洗牌和发牌
- socket通信基础(二)
- 在Android Studio中创建能调用C/C++函数的APK
- canvas和svg
- 【转】Java线程:新特征-锁(1)
- OBS源码分析--视频采集显示
- 七牛云上传
- struts2+spring4.0+hibernate4三大框架的结合,关于struts.xml的存放位置问题