Backport of recent changes to `$location` to v1.2.x