user1966211
user1966211

Reputation: 873

Backbone Router with parameter not working

I'm trying to use backbone routes with parameters and for some reason, I just can't seem to make the code below to work:

var App = new Backbone.Marionette.Application();

App.Router = Backbone.Router.extend({
    routes: {
        "export": "export",
        "show": "show/:id", // This just won't work
        "providers": "providers"
    },

    export: function() {
        var exportView = new App.ExportView();
        exportView.render();
        $("#main").html(exportView.el);
    },

    show: function(id) {
        console.log('from here'); // This is not even firing
        var show = this.collection.get(id);
        showView.render();
        $("#main").html(showView.el);
    },

    providers: function() {
        var contentProvidersView = new App.ProvidersView();
        providersView.render();
        $("#main").html(providersView.el);
    }
});

App.addInitializer(function() {
    var router = new App.Router();
});

Nothing happens when I try to access this: #show/2 (Where 2 is the show id)

Many thanks.

Upvotes: 0

Views: 459

Answers (1)

Ven
Ven

Reputation: 19040

It's the other way around :

routes: {
  "show/:id": "show",
}

Upvotes: 4

Related Questions