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
questions about pushState and history #456
Comments
Clicking HTML links certainly isn't compatible with pushState -- what would the link even be? Use: http://documentcloud.github.com/backbone/#Router-navigate |
ok thanks! but I can not use the 'Tab' to focus on the links.... I don't think that is a good user experience... |
(this is quite ghetto/oldschool, but should solve your problem)
(you can even the click handler elsewhere, this example is simply to show you how you could use it) |
Maybe too late but you can do like this : $('a').click(function (e) { app.navigate($(this).attr('href'), true); return false; }); And use links normally :
Like this, if the user doesn't have JavaScript, the link will be trigger by the server, otherwise by Backbone. |
Or, extending just a bit Atinux's example: window.document.addEventListener('click', function(e) {
e = e || window.event
var target = e.target || e.srcElement
if ( target.nodeName.toLowerCase() === 'a' ) {
e.preventDefault()
var uri = target.getAttribute('href')
app_router.navigate(uri.substr(1), true)
}
});
window.addEventListener('popstate', function(e) {
app_router.navigate(location.pathname.substr(1), true);
}); if you want to have actions bound to not yet loaded views' routes and a working back button. |
sorry.. noob here where would i place this code by pnbv or Atinux? |
The code need to be executed after the document was loaded. So you can put anywhere in your page but it need to be in the Jquery ready event : $(document).ready(function () { |
That's it. |
I'm not very sure that you need to have a server-side representation of each state. Indeed if Backbone JS catch the url when the page is loaded, there's no problem ? |
Yep, what I meant was that if you want urls instead of hashes then, in my opinion, it doesn't make sense to not have one. But, on the other hand, if your application hides the address bar or lives inside a native app then it doesn't make sense to have different urls at all. I think there may have been some confusion about the rational behind the history api. |
In my opinion there are two main use cases for Backbone.
|
hi,
I'm trying to upgrade Backbone in my project from 0.3.3 to 0.5.0 (d2082a5 ) and want to set pushState as true when call Backbone.history.start(), but ....
here is the code:
and
The project is ok on IE678.. but can't work on pushState-capable browser such as FF and Chrome...
when I click any link on homepage, the URL has changed but can not trigger the correctly events that defined in router...
Is there someting wrong with my code or Backbone latest version?
Thanks~
The text was updated successfully, but these errors were encountered: