larrymyers / react-mini-router

A minimal URL router for React.js
MIT License
282 stars 38 forks source link

does this support in page or hash links? #58

Closed EXC-BAD-ACCESS closed 8 years ago

EXC-BAD-ACCESS commented 8 years ago

i.e. <div id="chapter4"><a href="#chapter4">chapter4</a>

larrymyers commented 8 years ago

Yes. Hash urls are fully supported.

EXC-BAD-ACCESS commented 8 years ago

are they not supported when using history=true by chance? i have:

routes: { '/': 'home', '#chapter4': 'chapter4', // not sure if this is necessary i'm really expecting home to be called with a hash parameter of some kind }

home: function(path, params) { //... }

chapter4: function(path, params) { // ... }

and if i click the link from my first question the home function is called with path={"": undefined} params=undefined, and if i dump my state object state.path="/"

i'm using react-mini-router@2.0.0 from npm

larrymyers commented 8 years ago

Yes, you're mixing concepts here, it's undefined behavior. If you want to use pushState browser history it really only understands paths. Including hash or query params in the route definition really doesn't make sense.

EXC-BAD-ACCESS commented 8 years ago

fair enough. then is it either possible to tell react-mini-router to ignore my hash links, or is there any conceptual reason why the hash couldn't be retained and passed into the route functions so i could deal with the hash myself?

e.g. : chapter4: function(path, params, hash) // perhaps hash is a bad naming choice here

if the later doesn't break anything conceptually i'd happily submit a pull request for your review.

larrymyers commented 8 years ago

If you're using pushState is there something you need to capture in the hash that you couldn't via query param? usually if you're using browser pushState there's no need for the hash in the url.

EXC-BAD-ACCESS commented 8 years ago

back when i learned html (like 20 years ago so my knowledge is way out of date) there were two things that could happen when you clicked on a link:

1) it goes to a different page: <a href="/someotherpage">link</a> 2) it scrolls the browser to a location within the current page: <a href="#inpage">link</a>

so with react-mini-router all the type 1 links work fine, but all of the type 2 links are broken because react-mini-router is (i believe) intercepting them, dropping the "#inpage", and calling the route (so taking me to the correct page, but dropping the info needed to scroll).

maybe it's a well known thing (that i just don't know) that in a single page app type 2 links are just not done and you have to use some other tag like <button> with an onclick handler and scroll the page yourself?