1

I have a controller Login that save the previous route like that :

$scope.$on('$routeChangeSuccess', function (event, currentRoute, previousRoute) {
  security.previousRoute = previousRoute;
});

So I save the previousRoute in my factory security...

Inside that factory I need change my location using that ! How can I do that? I tried that :

security.previousRoute.reload();

but that Route object does not have the reload method...

Thanks

My previousRoute object:

| y {params: Object, pathParams: Object, $$route: Object, loadedTemplateUrl: "/app/template/user/index.html", reloadOnSearch: true…}
 -  $$route: Object
 - loadedTemplateUrl: "/app/template/user.html"
 -  params: Object
 -  pathParams: Object
 -  __proto__: Object
Paul
  • 12,359
  • 20
  • 64
  • 101
  • this will not work because $location.path require string variable i recommend you using $locationChangeSuccess(newUrl, oldUrl).Meanwhile please wait for somebody else answer – Ajay Beniwal Apr 17 '13 at 18:30

1 Answers1

2

Just use $location property to set the url

$location.path(security.previousRoute);
Ajay Beniwal
  • 18,857
  • 9
  • 81
  • 99
  • 1
    Hello.. tried that and got thar error: TypeError: Object # has no method 'charAt' – Paul Apr 17 '13 at 18:04
  • Well i have used this quite few times could you share your fiddle – Ajay Beniwal Apr 17 '13 at 18:08
  • I added the previousRoute object (debug mode) ... It seems right to you? – Paul Apr 17 '13 at 18:20
  • 1
    I am also getting the "TypeError: Object # has no method 'charAt'" error. Is there a solution to that? – evermean Aug 10 '13 at 11:07
  • `charAt()` is something you'd do to a string, so it sounds like the object you're sending to `$location.path` isn't a string. Just a guess. :) – SimplGy Jan 17 '14 at 05:37
  • `$location.path()` expect its argument to be string. I have no idea why this answer is accepted and upvoted! – Alireza Mirian Oct 20 '14 at 20:44
  • Well basically code should be changed to `$location.path(security.previousRoute.originalPath)`. I think that should do the trick. Answer is probably accepted because it pointed OP in the right direction. – Robert Koritnik Oct 08 '15 at 20:11