backbone.js - Backbone router, pushstate, and relative urls -
i'm making first backbone app. have pushstate enabled. in router have 2 routes.
'link1(/)' : 'link1route', 'link2(/)' : 'link2route'
on link1 page, have link pointing link 2 so:
<a href="link2">link2</a>
i click on link, router takes on , go link2route expected. however, if hover on link, status bar indicates link @ domain.com/link1/link2 rather domain.com/link2. right given relative url construction on link1 page. unfortunately, if user decides open link in new window or tab, backbone's router not take effect. expected since opening in new window or tab results in new page load server. problem of course, domain.com/link1/link2 not exist.
what ways of dealing situation? thanks.
as mateusmaso indicated, need alter link target "/link2" (i.e. including "/").
in addition, when implementing pushstate, don't forget need server respond content if user requests "domain.com/link2" url. response can index.html
if wish, server must homecoming page url.
if homecoming index.html
backbone-related urls, when backbone app gets started route-handling code fired , proper info displayed.
if want larn more routing , how manage without needing pass trigger: true
when calling navigate
, check out pages 32-46 of free sample pdf: http://samples.leanpub.com/marionette-gentle-introduction-sample.pdf (full disclosure, i'm book author)
backbone.js pushstate backbone-routing
No comments:
Post a Comment