Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

backbone.js and routing

I'm not sure if either im doing something wrong, But I have a function in my router set up like so:

    ":page/"    : "page",
    ":page/:subpage"    : "subpage"

but if the user were to access :page without the forward slash my page function breaks. I've tried adding another function without the forward slash and it breaks it somehow.

  ie: ":page":"page"
      ":page/":"page"
      ":page/:subpage/":"subpage"
like image 591
Robert Avatar asked Dec 05 '25 02:12

Robert


1 Answers

you can do the following to fix the issue:

var Router = Backbone.Router.extend({
      routes: {
      'page(/)': 'page',
      ":page:subpage(/)"    : "subpage"
    }
});
like image 128
Nam Bok Inator Avatar answered Dec 07 '25 16:12

Nam Bok Inator



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!