gpt4 book ai didi

javascript - 在 Angularjs ui-router 中获取以前的位置

转载 作者:搜寻专家 更新时间:2023-11-01 05:01:05 25 4
gpt4 key购买 nike

我知道我们可以在 $stateChangeSuccess 中使用 fromStatefromParams 来获取有关先前位置的所有信息。就像这里说的:

Angular - ui-router get previous state

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {

});

但是有没有好的方法将它解析成url/location呢?例如:

State: /page/:id/paragraph/:line

Params: id and line, etc..

我想要的:

/page/3/paragraph/5 ...

我的意思是这可能会因为一堆参数而变得困惑。另外 Angularjs ui-router 也可以将 {{ id }} 作为参数而不是 :id。是否已经有执行此操作的功能,或者我必须使用 RegEx?如果是这样,要使用的 RegEx 字符串是什么?

谢谢。

最佳答案

使用$state.href获取url:

$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {

// $state.href(from, fromParams)

});

您还可以将选项作为第三个参数传递。
Read the Docs获取更多信息。

关于javascript - 在 Angularjs ui-router 中获取以前的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21210699/

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