Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix smooth scroll breaking back button #1767 #1786

Closed
wants to merge 1 commit into from

Conversation

danieljl
Copy link

Fix #1767.

@mmistakes
Copy link
Owner

Is there any way to make the URLs that appears in the browser bar match the ones on the page?

When testing this fix on the /test site content and a page with a table of contents. All of the URL's there are /#hash. When clicking on them the URL bar changes to /#/hash. And if you share those URLs they don't scroll down to the appropriate location.

Where as /#hash does.

image

image

@danieljl
Copy link
Author

All of the URL's there are /#hash. When clicking on them the URL bar changes to /#/hash.

Yeah, I noticed that too. However, I honestly don't have much experience with JavaScript. I just copied the code snippet you posted, which was from the link I gave to you. If you know how not to add an extra slash, you can tell me and I'll update the PR.

And if you share those URLs they don't scroll down to the appropriate location.

They do scroll down for me.

@mmistakes
Copy link
Owner

They scroll for me when clicking fine. What I'm concerned about is if those links get indexed or shared and someone clicks on it from an external source or different page, then it doesn't load at the proper heading. It just starts at the top of the page.

I'll take a look at the script and see if I can alter the regex to keep /#hash instead of replacing it with /#/hash.

@danieljl
Copy link
Author

What I'm concerned about is if those links get indexed or shared and someone clicks on it from an external source or different page, then it doesn't load at the proper heading. It just starts at the top of the page.

How did you test it? The way I tested was by copying the link with a hash and pasting in a new tab (not in the current tab). And the loaded page started at the section the hash referred to.

@mmistakes
Copy link
Owner

/#/hash doesn't work when JavaScript is disabled.
/#hash does work when JavaScript is disabled because it's a valid anchor due to the headline elements having id="hash" attributes.

@mmistakes
Copy link
Owner

mmistakes commented Aug 14, 2018

Digging into this further on jQuery Smooth Scroll GH issues, seems like there are legit reasons to doing /#/hash.

I'd be fine with that solution, but I still don't like that they won't work if JS is disabled. Which is probably rare these days, but still. I also don't like how there's a mixture of different path types. In the raw HTML you get /#hash, but those who might click a hash link and then copy/paste from the address bar will get /#/hash. That seems messy to me.

Still digging around to see if there are other options. Some of the solutions I've found mention using jQuery BBQ, but I'd like to avoid throwing even more JavaScript at the problem.

@stale
Copy link

stale bot commented Sep 13, 2018

This issue has been automatically marked as stale because it has not had recent activity.

If this is a bug and you can still reproduce this error on the master branch, please reply with any additional information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in 7 days if no further activity occurs. Thank you for all your contributions.

@stale stale bot added the Status: Stale label Sep 13, 2018
@stale stale bot closed this Sep 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants