在ui-router中,如何只重新解析最本地的状态? [英] in ui-router, how to re-resolve only the most local state?

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

问题描述

我有以下状态树,使用 ui-router,

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

home 当用户在 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})

当我尝试时,从home

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

这导致 一切root 向下得到重新解析,这是有问题的,而且很昂贵,因为我只需要重新解析 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?

谢谢

推荐答案

一个 wokring 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, },
  ...
})

我们可以看到,我们根本没有接触url.它永远不会有任何变化,只是 /dashboard

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

但我们引入了最新版本的非常酷的功能 - params: {}.它定义了一些参数 - 在我们的例子中是 updater.每当这个参数被发送,并且与它的当前值不同时,这个子状态(并且只有这个子状态)重新初始化

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

此处

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

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