Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

fix($location): fix handling of hash fragment links #10190

Closed
wants to merge 1 commit into from

Conversation

urish
Copy link

@urish urish commented Nov 22, 2014

This commit adds a new fixHashFragmentLinks method to $locationProvider. This method fixes incorrect rewriting of hash fragment links. In order to use in your project, you need to enable the new behavior:

myApp.config(function($locationProvider) {
  $locationProvider.fixHashFragmentLinks(true);
});

In addition, you need to inject the $anchorScroll service to one of your controllers/services, to enable automatic anchor scrolling.

Closes #8675

@googlebot
Copy link

Thanks for your pull request.

It looks like this may be your first contribution to a Google open source project, in which case you'll need to sign a Contributor License Agreement (CLA) at https://cla.developers.google.com/.

If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check the information on your CLA or see this help article on setting the email on your git commits.

Once you've done that, please reply here to let us know. If you signed the CLA as a corporation, please let us know the company's name.

@urish
Copy link
Author

urish commented Nov 22, 2014

CLA done

@googlebot
Copy link

CLAs look good, thanks!

This commit adds a new `fixHashFragmentLinks` method to `$locationProvider`. This method fixes incorrect rewriting of hash fragment links. In order to use in your project, you need to enable the new behavior:

```js
myApp.config(function($locationProvider) {
  $locationProvider.fixHashFragmentLinks(true);
});
```

In addition, you need to inject the `$anchorScroll` service to one of your controllers/services, to enable automatic anchor scrolling.

Closes angular#8675
@urish urish force-pushed the fixHashFragmentLinks branch from 6172383 to a1f8378 Compare November 22, 2014 23:59
@urish
Copy link
Author

urish commented Nov 23, 2014

Seems like the build has errored - is there any way to run it again?

@IgorMinar IgorMinar added this to the ng-fixit #1 milestone Nov 24, 2014
loadFixture("ng/location/hashFragmentScrolling").andWaitForAngular();
});

it('should scroll to the element whose id appears in the hash part of the link', function() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test is causing an error in Travis (and looks like it's causing all subsequent tests to fail).

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this reproduce? A similar line already exists in this test, so I don't see a reason why it would break here...

@jeffbcross jeffbcross self-assigned this Nov 24, 2014
@shahata
Copy link
Contributor

shahata commented Nov 26, 2014

Ahalan @urish - I restarted your build and it is passing now. Next time you can do it yourself simply by doing git commit --amend --no-edit; git push -f on your branch

@urish
Copy link
Author

urish commented Nov 26, 2014

Thanks @shahata !

@petebacondarwin
Copy link
Contributor

This is not really a sensible solution, since it then prevents users from using routing. Instead a better workaround is just to provide a hash prefix, such as !. See #8675, I suggest that we implement the ! as the default rather than an empty string.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$location injection causes / insertion after hash on page refresh when not in html5mode
6 participants