backbone.js - Backbone Router does not trigger for direct URLs - using Meteor -


i using same basic router code todo's example, running issues. when router.navigatetoitem(itemid) works. however, if enter in direct url (/inventory/itemid), session variable never set , direct url doesnt work. can figure out how router trigger via direct url. thank appreciated. here's code i'm working with:

var webrouter = backbone.router.extend({     routes: {       "": "main",       "inventory/:itemid": "itemdetail"     },     main: function () {       session.set("inventoryitem", null);     },     itemdetail: function(itemid) {       session.set("inventoryitem", items.find({_id:itemid}).fetch()[0]);     },     navigatetoitem: function(itemid) {       this.navigate("inventory/"+itemid, {trigger: true});     }   });    router = new webrouter;    meteor.startup(function () {     backbone.history.start({pushstate: true});   }); 

edit 1:

i notices if not pushstate:

backbone.history.start(); 

then seems work. however, have stupid hash symbol in url , dont know came from: /#inventory/wsl7yzxiwk3cv3cgt

getting closer... i'm unsure lost without pushstate...

edit 2:

another failed attempt:

  window.onload= function(){     var url = window.location.pathname;     router.navigate(url.substring(1,url.length), {trigger: true});     console.log(url.substring(1,url.length));   }; 

i thought 1 going work, doesnt...

you need configure server redirect urls serve content gets served when requesting root. backbone handles url after page has been loaded, if don't have server configured handle urls backbone never loaded because html never gets sent.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -