Hasher
Hasher copied to clipboard
Use without hasthag
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?
Realized it's the wrong place for this question and asked it again here: https://github.com/millermedeiros/crossroads.js/issues/126
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
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?
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!
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 :).
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?
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?
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:
- Handling history.pushSate
- 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
- making sure, your server knows to serve to serve HTML on every route
- Handling all the clicks to links
- I'm pretty sure I'm forgetting something
and I'm pretty sure, there are easier ways to this.