使用 Angular ui-router 在不改变状态的情况下设置 URL 查询参数 [英] Set URL query parameters without state change using Angular ui-router

查看:35
本文介绍了使用 Angular ui-router 在不改变状态的情况下设置 URL 查询参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我应该如何使用 AngularJS 的 ui-router 更新带有更改查询参数的地址栏 URL 以在刷新页面时保持状态?

How should I update the address bar URL with a changing query parameter using AngularJS' ui-router to maintain state when refreshing the page?

目前,我正在使用 $state.transitionTo('search', {q: 'updated search term'}) 每当输入更改时,但问题是这会重新加载控制器,重新绘制窗口并失去任何文本输入焦点.

Currently, I am using $state.transitionTo('search', {q: 'updated search term'}) whenever input changes, but the problem is that this reloads the controller, redraws the window and loses any text input focus.

有没有办法更新 stateParams 并将其同步到窗口 URL?

Is there a way to update stateParams and sync it to the window URL?

推荐答案

我在使用 .transitionTo 之前遇到了问题,直到我更新为 用户界面路由器 0.2.14.0.2.14 使用如下调用正确更改位置栏(无需重新加载控制器):

I was having trouble with .transitionTo until I updated to ui-router 0.2.14. 0.2.14 properly changes the location bar (without reloading the controller) using a call like this:

$state.transitionTo('search', {q: 'updated search term'}, { notify: false });

这篇关于使用 Angular ui-router 在不改变状态的情况下设置 URL 查询参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆