如何在州内进行转换?

时间:2021-09-17 20:41:07
$stateProvider.state("browse", {
  url : "/browse/{id}",
  controller : "BrowseCtrl",
  templateUrl : "browse.html"
});

I will be frequently transitioning from /browse/1 to /browse/2 (and /browse/3 and /browse/400).

我将经常从/ browse / 1转换到/ browse / 2(和/ browse / 3和/ browse / 400)。

ui-router's natural behavior is to reload the template and reload the controller. That is not what I want.

ui-router的自然行为是重新加载模板并重新加载控制器。那不是我想要的。

What I want is for the controller (or somebody) to be notified "you used to be at /browse/1; now you are at /browse/2. Handle it." My code will update the screen as necessary (by doing a clever animation from 1 to 2).

我想要的是控制器(或某人)被通知“你曾经在/ browse / 1;现在你在/ browse / 2。处理它。”我的代码将根据需要更新屏幕(通过从1到2进行巧妙的动画)。

If, however, the transition is from some other state, then I would like it to do the ordinary thing: load the template and the controller.

但是,如果转换是来自其他某个状态,那么我希望它能做普通的事情:加载模板和控制器。

All my searches have turned up is fancy ways to animate transitions out of one state and into another, which is not what I want to do.

我所有的搜索都出现了一种奇特的方式,可以将转换从一个状态转移到另一个状态,这不是我想做的事情。

Nor (so far as I can tell) is this "sticky". A sticky state would maintain its scope from one invocation to another -- I want to keep the scope only as long as the transitions are within this state.

也不是(据我所知)这是“粘性的”。粘性状态会将其范围从一次调用维持到另一次调用 - 只要转换处于此状态,我只想保留范围。

I am sure there is a keyword or an option or something for this, I just cannot find it.

我确信有一个关键字或选项或其他东西,我只是找不到它。

EDIT: It occurs to me that I could accomplish all this if I could just mark {id} as not being important; that {id} changing does not constitute a transition and the only reaction to the change is that $stateParams is updated.

编辑:如果我能将{id}标记为不重要,那么我可以完成所有这些。 {id}更改不构成转换,对更改的唯一反应是$ stateParams更新。

1 个解决方案

#1


I think best is to have different states, in your case browser.one, browser.two, browser.three and so on.

我认为最好是拥有不同的状态,例如browser.one,browser.two,browser.three等等。

Check this detailed answer for sharing data between states.

检查此详细答案,以便在状态之间共享数据。

#1


I think best is to have different states, in your case browser.one, browser.two, browser.three and so on.

我认为最好是拥有不同的状态,例如browser.one,browser.two,browser.three等等。

Check this detailed answer for sharing data between states.

检查此详细答案,以便在状态之间共享数据。