1

I'm looking for a way to retrieve the path name of the current route as I define it in $routeProvider, i.e. /customer/:id.

$location.path() returns the path, /customer/1, but not the path name, /customer/:id.

I have found $route.current.$$route.originalPath that returns exactly what I need. However, I would like very much to not have to rely on private methods.

Is there a public equivalent of $route.current.$$route.originalPath?

Mihai Dinculescu
  • 19,743
  • 8
  • 55
  • 70

3 Answers3

1

Not sure if you found another way to do this, and happened to come across this question while I was debugging some routing issues -

AFAIK the only way to get exactly what you need is to use:

$route.current.$$route.originalPath

Another way to handle this is using the broadcasted events like routeChangeStart/routeChangeSuccess to officially know which route was resolved.

$rootScope.$on('$routeChangeSuccess', function (event, next, prev) {
    console.log(next.$$route.originalPath);
});
jarodsmk
  • 1,876
  • 2
  • 21
  • 40
1

Try

$route.current.originalPath
Amaldev ps
  • 257
  • 2
  • 12
0

You can use

$state.$current.url.sourcePath

But it is a little bit hacky too :)

Boris Parnikel
  • 863
  • 1
  • 7
  • 15
  • Why do you say it's hacky? – Mihai Dinculescu Mar 06 '16 at 20:34
  • Don't know, maybe it's because i've never used unresolved state url directly in state, so for me using of '$current' is a strange by the fact at all:) Note that you can also access unresolved state url in $stateChangeStart and $stateChangeSuccess listeners on $rootScope in second parameter (toState) – Boris Parnikel Mar 06 '16 at 20:38
  • 1
    Sadly this is for `ui-router`. I was looking for a solution for `ngRoute`. – Mihai Dinculescu Mar 06 '16 at 21:30