gpt4 book ai didi

angularjs - 单击链接时强制重新加载路线/状态

转载 作者:行者123 更新时间:2023-12-03 00:25:19 29 4
gpt4 key购买 nike

目前我正在做这样的事情

link.on('click', function () {
if (link.attr('href') !== $route.current.originalPath)
return;
$route.reload();
});

我不知道有副作用,但我想可能会有一些。

在 ngRoute 中是否有更直接的方法来处理这个问题,例如通过$location

当应用程序更新以使用 UI Router 时,如何在 UI Router 中执行相同的操作?

最佳答案

使用 UI-Router,我们有一组选项,其中一个是 {reload: true}

go(to, params, options)

  • location - {boolean=true|string=} - If true will update the url in the location bar, if false will not. If string, must be "replace", which will update url and also replace last history record.
  • inherit - {boolean=true}, If true will inherit url parameters from current url.
  • relative - {object=$state.$current}, When transitioning with relative path (e.g '^'), defines which state to be relative from.
  • notify - {boolean=true}, If true will broadcast $stateChangeStart and $stateChangeSuccess events.
  • reload (v0.2.5) - {boolean=false}, If true will force transition even if the state or params have not changed, aka a reload of the same state. It differs from reloadOnSearch because you'd use this when you want to force a reload when everything is the same, including search params.

因此我们可以强制状态重新加载:

$state.go("stateName", stateParams, {reload: true});

关于angularjs - 单击链接时强制重新加载路线/状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33442764/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com