What you need is a place where you can check for that parameter every time the URL changes. Since the .config method is only called the one time (when the app is ... err.. configured), you could use the .run method instead.
So, let's assume that your query item is called returnTo. I like the way that sounds.
I'm assuming you have a routeProvider config call similar to this:
YourAngularApp.config(['$routeProvider', function ($route) {
.... code for routes here ....
}]);
And, lets assume you have a call to your service that looks like this:
https://any.doma.in/#/a?returnTo=https://origin.al/url
Oops... wait. That won't work. That little "?" comes after your # ... so the browser will actually go back in time. It will literally travel backward 2 seconds and leave you in the same programmer loop forever unless you break the cycle and restore proper order to the universe. Until you do, you'll be stuck in that Aeron like a pear-shaped Sisyphus.
https://any.doma.in/?returnTo=https%3A%2F%2Forigin.al%2Furl%0D%0A#/a
OK. I feel better. Now what? Well ... back to that .config call above. We can just append a .run method call to the bottom of that file:
YourAngularApp.run(['$rootScope','$location', function($rootScope, $location) {
$rootScope.$on('$locationChangeStart', function (event, newUrl, oldUrl) {
var myParameterValue = getParameterByName('returnTo');
if(myParameterValue != '') {
$rootScope.returnTo = myParameterValue;
//do whatever it is you want to do with that parameter here.
}
});
function getParameterByName(name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
}
}]);
Note that I'm adding a little getParam method that I yanked from here because
(a) thought the code should be complete in the post and
(b) I assume you don't want to include the parameter as an optional parameter on every one of your angular routes and
(c) I assume you hate jQuery (seems to be alot of that going around in the angular community).
Not sure what you need to do, but I'm guessing you can take a look at settings in $rootScope to figure out what steps to take with returnTo... this will get you that parameter's value in the same codeblock as $rootScope and $location ... You should be able to take it from here!
And - this gets you access without having to remember to code it into every route in your app! Just don't forget that pesky url formatting stuff above. Good luck!