在用户界面的路由器,如何重新解析只有最本地状态? [英] in ui-router, how to re-resolve only the most local state?

查看:201
本文介绍了在用户界面的路由器,如何重新解析只有最本地状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下的州树,使用的UI路由器,

I have the following state tree, using ui-router,

1 login
2 root (abstract, resolves app-prefs, user-prefs)
    2.1 home (builds a refresh button, should refresh whatever is being shown)
        2.1.1 dashboard (resolves dashboard-prefs)
        2.1.2 search (resolves search-prefs)
        2.1.3 etc
    2.2 etc

首页当用户presses刷新按钮,而在 XYZ 的状态,我想有 XYZ 重新进入以这样一种方式,它重新解析自己的 XYZ-preFS 但不是东西以上层次。类似

From home when user presses refresh button while in XYZ state, I would like to have the XYZ re-entered in such a way that it re-resolves its own XYZ-prefs but not things above in hierarchy. Something like

$state.go("dashboard", dashboardParams, {please-resolve-only-dashboard})

当我尝试从首页

$state.go("dashboard", dashboardParams, {reload:true})

这导致的所有的从下得到重新解决,这是个问题,而且价格昂贵,因为我需要重新解析只 dashboard- preFS 。我可以设置一些解析器更精细的计划,不会重新自行解决,但可能成为本身就是一个任务我害怕。是否有另一种,更地道的方式?

that causes everything from root downwards to get re-resolved, which is problematic, and expensive, as I need to re-resolve only dashboard-prefs. I can setup a more elaborate scheme in some resolvers to not re-resolve themselves but that might become a task by itself I'm afraid. Is there another, more idiomatic way?

感谢

推荐答案

一个工作呢plunker

有是土生土长的路该怎么做 - 只是改变你要重新加载状态参数。

There is a native way how to do that - just change the parameter of the state you want to reload.

要复制上面的状态定义让我们这样定义的仪表板:

To reproduce the above state definition let's have dashboard defined like this:

.state('dashboard', { 
  parnet: 'home',
  url: "^/dashboard",
  params: { updater : 1, },
  ...
})

我们可以看到,我们没有触摸 网​​址 在所有。这将永远是没有任何变化只是 /仪表板

What we can see, that we do not touch url at all. It will always be without any change just /dashboard

但是,我们引进的最新版本很酷的功能 - params:一个{} 。它定义了一些参数 - 在我们的例子更新。每当这个参数被发送出去,并形成不同的电流值,这个孩子的状态的(只有这个孩子状态)的就是重新初始化

But we introduce really cool feature of the latest version - params: {}. It defines some parameter - updater in our case. Whenever this parameter is sent, and does differ form its current value, this child state (and only this child state) is re-init

检查它更多的状态 params:一个{} 此处的http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider

Check it more about state params: {} here: http://angular-ui.github.io/ui-router/site/#/api/ui.router.state.$stateProvider

现在,我们可以创建这个重载链接:

Now, we can create this reload link:

<a ui-sref="dashboard({updater : ($stateParams.updater + 1) })">reload</a>

和与此增量,我们可以肯定,重装会的重新加载此状态

And with this incrementation, we can be sure, reload will reload this state

检查一下这里

这篇关于在用户界面的路由器,如何重新解析只有最本地状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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