I know we can use fromState
and fromParams
in the $stateChangeSuccess
to get all information about previous location. Like said here:
我知道我们可以在$ stateChangeSuccess中使用fromState和fromParams来获取有关以前位置的所有信息。就像这里说的:
Angular - ui-router get previous state
Angular - ui-router获得以前的状态
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
});
But is there nice way to parse it into the url / location though? For example:
但有没有很好的方法来解析它到网址/位置?例如:
State: /page/:id/paragraph/:line
Params: id and line, etc..
参数:id和line等。
What I want:
我想要的是:
/page/3/paragraph/5 ...
I mean this could get messy with bunch of params. Plus Angularjs ui-router
could also have {{ id }}
as params too instead of :id
. Isn't there a function to do this already or I have to use RegEx? And if so, what is the RegEx string to use?
我的意思是这可能会被一堆参数弄得一团糟。加上Angularjs ui-router也可以{{id}}作为参数而不是:id。是否有功能这样做或我必须使用RegEx?如果是这样,RegEx字符串使用什么?
Thanks.
3 个解决方案
#1
9
Use $state.href
to get the url:
使用$ state.href获取url:
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
// $state.href(from, fromParams)
});
You can also pass options as a third paramerer.
Read the Docs for more information.
您还可以将选项作为第三个参数传递。阅读文档了解更多信息。
#2
3
Not much differently, but you could do:
没有太大的不同,但你可以这样做:
$rootScope.$on('$routeChangeStart', function (event, next, current) {
});
And just store the current. The function there is a lot less to deal with than $routeChangesuccess
.
并存储当前。这个函数比$ routeChangesuccess要少得多。
#3
-2
using window.history.back()
will return you to the previous url.
使用window.history.back()将返回上一个url。
#1
9
Use $state.href
to get the url:
使用$ state.href获取url:
$rootScope.$on('$stateChangeSuccess', function (ev, to, toParams, from, fromParams) {
// $state.href(from, fromParams)
});
You can also pass options as a third paramerer.
Read the Docs for more information.
您还可以将选项作为第三个参数传递。阅读文档了解更多信息。
#2
3
Not much differently, but you could do:
没有太大的不同,但你可以这样做:
$rootScope.$on('$routeChangeStart', function (event, next, current) {
});
And just store the current. The function there is a lot less to deal with than $routeChangesuccess
.
并存储当前。这个函数比$ routeChangesuccess要少得多。
#3
-2
using window.history.back()
will return you to the previous url.
使用window.history.back()将返回上一个url。