Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
17
rated 0 times [  20] [ 3]  / answers: 1 / hits: 11517  / 11 Years ago, sat, january 18, 2014, 12:00:00

I know we can use fromState and fromParams in the $stateChangeSuccess to get all information about previous location. Like said here:


Angular - ui-router get previous state


$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..



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?


Thanks.


More From » regex

 Answers
12

Use $state.href to get the 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.


[#48567] Friday, January 17, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
makaylahk

Total Points: 166
Total Questions: 94
Total Answers: 117

Location: Gabon
Member since Sat, Jul 25, 2020
4 Years ago
;