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

Use without hasthag #69

Open
martinsookael opened this issue Mar 18, 2015 · 8 comments
Open

Use without hasthag #69

martinsookael opened this issue Mar 18, 2015 · 8 comments
Labels

Comments

@martinsookael
Copy link

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
Copy link
Author

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

@millermedeiros
Copy link
Owner

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

@martinsookael
Copy link
Author

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
Copy link
Author

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
Copy link
Author

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 martinsookael reopened this Mar 22, 2015
@martinsookael
Copy link
Author

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?

@egucciar
Copy link

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?

@martinsookael
Copy link
Author

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.

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

No branches or pull requests

3 participants