fix($location): revert erroneous logic and backport refactorings from master

Backport of 22948807e324eb0b182b15b31045dc306a9f3231 without enforcing the `<base>` tag and without the new handling for links that only contain hash fragments.

Related to #6162
Closes #8492