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

handling both hash routing & anchor links #440

Closed
sethvincent opened this issue Mar 23, 2017 · 11 comments · Fixed by #667
Closed

handling both hash routing & anchor links #440

sethvincent opened this issue Mar 23, 2017 · 11 comments · Fixed by #667

Comments

@sethvincent
Copy link
Contributor

As I'm porting minidocs to choo v5 I'm working on making choo v5 support both hash routing & navigating to anchor links if they are present on the page.

The tricky part is that when the router is first called, the element isn't available on the page yet: https://github.com/yoshuawuyts/choo/blob/master/index.js#L50

So there's not a way to check if an id is available to scroll to before the router is called.

Thoughts on how to implement this?

@sethvincent
Copy link
Contributor Author

Forgot to add:

Current behavior of createLocation function is to rewrite a url fragment like /about#install to /about/install before it is passed to the router.

The goal (I think) is to avoid this behavior when the #install id exists on the page, and only tell the router the pathname in that case.

@jenslind
Copy link

jenslind commented Apr 7, 2017

Instead of checking if the id exists, perhaps we could prefix the hash if we want to use it as an anchor. Something like this: /route#anchor:id, just a thought.

@yoshuawuyts
Copy link
Member

yoshuawuyts commented Apr 8, 2017 via email

@jenslind
Copy link

jenslind commented Apr 8, 2017

Totally agree!

Another thought off the top of my head.. 💭
Having # behaving differently depending on page content feels a bit weird to me.
What about an option to turn off support for # in routes, i.e. do not turn /some#route into /some/route. And let the user make the choice of treating # as a path or anchor.

🐈

@tornqvist tornqvist mentioned this issue May 29, 2017
15 tasks
@yoshuawuyts
Copy link
Member

@jenslind generally I'm not a big fan of options, but as per #489 by exposing the app._createRoute method the behavior can be changed if people wish to. Hope this good enough! :D

@hbrls
Copy link

hbrls commented Jul 3, 2017

Do you have a hash routing example? I cannot get it to work.

@bcomnes
Copy link
Collaborator

bcomnes commented Jul 3, 2017

@LJNGDAHL
Copy link

LJNGDAHL commented Dec 6, 2017

As a fairly new user of choo (and so far overall super impressed by it 🎉) I’m having a bit of trouble understanding the way anchor links are handled. How come you have decided to turn /some#route into /some/route?

It took awhile for me to wrap my head around what the section Hash routing in the README.md really meant (and how to get anchor links working like they usually do) – but that might just be me as a confused newbie. 🤔 ✨

@johnelliott
Copy link

johnelliott commented Dec 10, 2017

It seems like the always-there default to top (<a href="#">top</a>)is does not with by default with nanohref. It would be nice if that worked unless a route is set on #.

@sonn-gamm
Copy link

hash routing works 'out of the box' except when you are at the root page and have a link bringing somewhere to that page — in which case a / is added before the #link.

how do you prevent that?

@istvanvasil
Copy link

istvanvasil commented May 15, 2018

hash routing works 'out of the box' except when you are at the root page and have a link bringing somewhere to that page — in which case a / is added before the #link.

how do you prevent that?

Any success on this?
@afincato

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

Successfully merging a pull request may close this issue.

9 participants