Check the questions:
My solution to this was the following:
Object.getPrototypeOf($route.current) === $route.routes['/Home'];
Given that the route object might be empty after you instantiate your controller, you should use the $routeChangeSuccess
event, like this:
$rootScope.$on('$routeChangeSuccess', function(e, curr, prev) {
if (Object.getPrototypeOf($route.current) === $route.routes['/Home']) {
// do something when route changes to /Home
}
else if (Object.getPrototypeOf($route.current) === $route.routes['/About']) {
// do something when route changes to /About
}
}
There's no need for declaring additional properties (although it would be nice if angular allowed it). You just use the pattern string.
As I've said in those other 2 questions, this is behavior is not documented (both $route.current and $route.routes are documented, but the prototype inheritance between them is not), so use it at your own risk.
Also this works on IE9+.