Advertisement
Guest User

Meteor Router with history support

a guest
Jan 5th, 2013
715
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ###
  2.   MainApp Router
  3. ###
  4. AppRouter = Backbone.Router.extend
  5.   routes:
  6.     '*path' : 'main'
  7.  
  8.   main: (url_path) ->
  9.     Session.set 'page_id', url_path
  10.  
  11. Router = new AppRouter
  12.  
  13.  
  14. ###
  15.   History Support
  16. ###
  17. Backbone.history.start
  18.   pushState: true
  19.  
  20. Session.set 'page_url', window.location.pathname
  21.  
  22. ###
  23.   Navigation - Listen for changes to Session.page_url and echo to Router
  24. ###
  25. Meteor.autorun (handle) ->
  26.   page_url        = Session.get 'page_url'
  27.   document.title  = page_url
  28.  
  29.   Router.navigate page_url, true
  30.  
  31. ###
  32.   Pathchange Support
  33. ###
  34. $ () ->
  35.   $.pathchange.init() # setup event listeners, etc.
  36.  
  37.   $(window).pathchange(() ->
  38.     if Session.get('page_url') isnt window.location.pathname
  39.       Session.set 'page_url', window.location.pathname
  40.   ).trigger "pathchange"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement