olivernn / davis.js

RESTful degradable JavaScript routing using pushState
http://davisjs.com
532 stars 58 forks source link

Doesnt work if bookmarked #11

Closed asifashraf closed 13 years ago

asifashraf commented 13 years ago

I loved this plugin due to all features. but why does it call only default route when i use a bookmarked link. it works only and only with a tags like #something , is that a bug or you didnt add that feature. its crucial

olivernn commented 13 years ago

I'm not exactly sure what you mean, please could you elaborate?

What do you mean by bookmarked link & default route? Is this a problem you are having with a plugin or the library itself? What to you mean by "tags like #something"?

Perhaps if you posted some sample code and explain the behaviour you are expecting and the behaviour you are getting?

asifashraf commented 13 years ago

ok Let me explain it. (about plugin Davis js)

I have declared two routes.

(1)this.get('/Page',function() {alert('on page'; )});

(2)this.get('/#open-popup',function() {alert('on popup'; )});

I go to the url http://domain.com/page and I see alert with text "on page" === I have made an achor tag like [a href="#/open-popup" ]Open Link[/a] .....when I click on that link it shows popup with text "on popup" by clicking on link The url in the browser becomes http://domain.com/Page#/open-popup No issue SO FAR. all 100% well==== Now when I COPY this url http://domain.com/Page#/open-popup in clipboard, open a new tab in the browser and PASTE this url http://domain.com/Page#/open-popup === at this stage i expect a popup saying "on popup", but it says "on page" Even on the ADDRESS BAR OF BROWSER I SEE URL http://domain.com/Page#/open-popup Still it shows me message from the function of route number (1) ....When you should copy and paste a url with a HASH it should identify it on PAGE LOAD but it does not identify that url, it just identifies url without HASH....in my case the url http://domain.com/Page#/open-popup does work good only if i use it from ANCHOR tag, but if I copy this url http://domain.com/Page#/open-popup and paste in new browser window, it does not fire the route number (2), but it SHOULD.... that seems to be a glitch cuz in SAMMY or backbone etc the behavior is that if you COPY URL and paste in NEW Browser window it should fire the PERFECT match.... NOT just the other one.

olivernn commented 13 years ago

Ok, I understand now.

I would've expected loading a page such as http://example.com/page#/hash would run both a route matching /page and then a route matching #/hash, currently Davis will currently only run the /page route.

I think the main problem though is the mixing of hash based routing and non hash based routing, Davis wasn't designed to handle both of these at the same time. I would suggest not mixing hash routes with non hash routes.

If the open-popup route has no matching route on the server you may want to look into using state routes, you might implement them like this:

this.state('/open-popup', function () {
  alert('on popup')
})

Then to trigger this route you would do this:

app.trans('/open-popup')

This will add an entry to the history stack but will not change the url. There is more in the documentation under Davis.Router.

asifashraf commented 13 years ago

I would've expected loading a page such as http://example.com/page#/hash would run both a route matching /page and then a route matching #/hash, currently Davis will currently only run the /page route.

answer: When I copy http://example.com/page#/hash and paste in NEW TAB (new tab is important), I see that HASH Route does not match. That is my main issue.

I think the main problem though is the mixing of hash based routing and non hash based routing, Davis wasn't designed to handle both of these at the same time. I would suggest not mixing hash routes with non hash routes.

answer: In all routing systems all hashes run on the top of Non hashed. You will always go to /Page and that is your considered default route. Then you will click on a link which has #/HASH in its HREF Attribute. We can have such 10 links on page like #/hash-1 , #/hash-2 .... And all will change url and url will become http://domain.com/page#/hash-1 and http://domain.com/page#/hash-2 and so on. How in the world you can keep them separate from each other? Hashes are built on Non hash urls.

If the open-popup route has no matching route on the server you may want to look into using state routes, you might implement them like this: this.state('/open-popup', function () { alert('on popup') })

answer: Lets forget about SERVER for a while. I do not want to go to SERVER SIDE controllers yet. Let us talk about WHAT should happen on Client if there IS A MATCHING ROUTE.

Summary: In short If I have a url like http://gmail.com/mail#1234 and I open a new browser tab and paste this url. It should show me "Email Message" instead of my inbox. But in davis it will always open the inbox and will not open the detail of that email. And ROUTING Systems SHOULD address this case, otherwise they are really NOT USABLE and can only help 30% of issues. Davis is the FIRST system which does not address this MOST IMPORTANT ISSUE.

If davis has no fix for my problem, I am gonna look for another routing system them.

olivernn commented 13 years ago

I think you are missing the point.

Davis is specifically designed to work with pushState so that you can respond to requests on the client side in supported browsers and in unsupported browsers the server will respond. It can be made to work with hash based routing, using the Davis.hashRouting extension, but mixing the two is unsupported.

If you still want to mix hash based and pushState based routing then you will probably need to either patch the existing Davis.history object (specifically Davis.history.current) or implement your own Davis.location delegate. I suggest reading the docs for Davis.location to get an idea on what is involved.

Finally if you don't want to do either of these then I suggest you either find a library that was designed to do what you need or write your own.

asifashraf commented 13 years ago

ok, I will try to patch is first of all, cuz i loved everything in it.

olivernn commented 13 years ago

You will probably need to change the following method to look at the hash part of the url too and then do some logic on what should be returned.

  // Davis.history.js:133
  var current = function () {
    return window.location.pathname
  }