backbone.js - Routing with slashes in Backbone -


i trying use pushstate routing in backbone.js

the problem when try use routes contain slashes in between links, router function wouldn't called , console show error:

var router = backbone.router.extend({  routes: {     "work/mobileapps": "showportfolio"      },      showportfolio: function(){         alert('show portfolio'); } 

the showportfolio function never gets called in case. i've tried parameters, this:

var router = backbone.router.extend({  routes: {     "work/:section": "showportfolio"      },      showportfolio: function(){         alert('show portfolio'); } 

but problem still remains same.

however, if change route this:

var router = backbone.router.extend({  routes: {     "work-mobileapps": "showportfolio"      },      showportfolio: function(){         alert('show portfolio'); } 

it starts work.

so seems there's problem slashes. please , let me know mistake making.

thanks!

here's full code:

//set variables according production/development environment var production = 0; var rootpath = (production) ? "/" : "websitev2/code"; //--------------------------------------------------------------   var router = backbone.router.extend({      routes: {         "work/mobileapps": "showportfolio",         "about": "showabout",         "work": "showwork",         "": "showhome"     },      showportfolio: function(){          alert('show portfolio');          //$("#work-content").empty();     },      showabout: function () {          alert('show about');        },      showwork: function () {          alert('show work');     },  });  $(document).ready(function () {     window.router = new router();     backbone.history.start({         pushstate: true,         root: rootpath     });  }); 

in limited experience, have tried:

var router = backbone.router.extend({      routes: {         'work(/:section)': 'showportfolio'     },      showportfolio: function(section){         alert('show portfolio ' + section);     } }); 

as noted in comments, need reference routes hash:

http://localhost/websitev2/code/#work/mobileapps


Comments