Hasher icon indicating copy to clipboard operation
Hasher copied to clipboard

Use without hasthag

Open martinsookael opened this issue 9 years ago • 8 comments

Thank you for this awesome library!

I'm using it with: https://github.com/jayJs/jay and https://github.com/jayJs/node-jay

Signals and Crossroads are also involved.

Question: Current url: "www.domain.com/#/post/first-post" How I'd like it to be: "www.domain.com/post/first-post"

So the question is about what's the best strategy for achieving this?

martinsookael avatar Mar 18 '15 14:03 martinsookael

Realized it's the wrong place for this question and asked it again here: https://github.com/millermedeiros/crossroads.js/issues/126

martinsookael avatar Mar 18 '15 16:03 martinsookael

hasher only handles location.hash, you need to implement your own abstraction around popstate and history.pushSate: https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Manipulating_the_browser_history

millermedeiros avatar Mar 18 '15 17:03 millermedeiros

So as I'm interested in the question I started to figure out a way to hack it. As a surprise I found myself back in the hasher library. I hope you don't mind me asking the question here.

https://github.com/millermedeiros/Hasher/blob/master/dist/js/hasher.js#L80 If instead of regexing it would analyze the URL and return everything after window.location.host might that be a solution?

One of the problems are cases when aplications are not in root folders. Is there anything else I'm not seeing?

martinsookael avatar Mar 20 '15 22:03 martinsookael

The other thing I was not seeing is that links like this require the whole page to load again.

The third is is that if the link is without a hashtag then the next time the link is presented as "#/newlink" then it will be turned into "domain.com/link#newlink" which requires me to rething linking.

Neverthelss if I tried this:

        var host = window.location.protocol + "//" + window.location.host
        var href = window.location.href

        if(href.charAt(host.length+1) === "#") {
          var result = _hashValRegexp.exec(hasher.getURL());
        } else  {
          var clean = href.replace(host, '')
          var result = []
          result.push(clean)
          result.push(clean)
        }

it enabled my app to receive both "domain.com/#/link" and "domain.com/link" the same way, which is something!

it's something

martinsookael avatar Mar 21 '15 19:03 martinsookael

I just built a Wordpress theme relying on Signals, Hasher and Crossroads.

https://github.com/jayJs/wp-jay

Bet you did not see that one coming.

Since Crossroads has so many subscribers I think this thread here might be the best place to continue discussion about removing the hash from URL.

If I could pick any person from the world to talk about that specific topic, then I think it would be you :).

martinsookael avatar Mar 22 '15 00:03 martinsookael

So sorry for bother you with this again. The same question came up as I was trying to find clever hacks for Single Page App SEO.

Since everything after "#" is not sent to the server by crawler, it might actually make sense to have

http://site.com/#/page-1 and http://site.com/page-1

respond with the same content.

Could this argument turn this question into a feature request?

martinsookael avatar May 25 '15 16:05 martinsookael

want to know if this is possible. Trying to integrate our SPA into another framework, so it is having issues with the # and handling it in unexpected ways. I find though if i used ? in the url I can bypass the other framework's handling of the #. Anyway to change?

egucciar avatar Jan 12 '16 20:01 egucciar

I've implemented it here: http://uudised.ngo.ee

and here: http://merilinmandel.com/gallery/portrait

It did require the above mentioned addition to Hasher, I implemented it here: https://github.com/jayJs/jay/blob/master/extra/shredder.js

Somebody just tell me, if this should be a pull request - I consider it a mere hack, since it's not the only requirement needed, to make hashtagless routing work.

The other things necessary are:

  1. Handling history.pushSate
  2. removing "#" from the URL when needed: https://github.com/jayJs/jay/blob/master/dist/jay.js#L489 and putting it back when needed: https://github.com/jayJs/jay/blob/master/dist/jay.js#L450
  3. making sure, your server knows to serve to serve HTML on every route
  4. Handling all the clicks to links
  5. I'm pretty sure I'm forgetting something

and I'm pretty sure, there are easier ways to this.

martinsookael avatar Jan 12 '16 21:01 martinsookael