Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor app - Backbone router not getting called

In my Meteor app Backbone routers are only working when the user is logged in (via the accounts-base package). It's strange. This router itself works fine. The showSaying()function isn't being called at all when the user is not logged in.

Below is the code in client.js within the client folder. Do I need to do something with sessions or auto-publishing?

AphorismView = Backbone.View.extend({
el: "#aphorism-item",
initialize: function(){
    _.bindAll(this, "render");
    this.render();
},
render: function() {
    this.$el.append("<p style='height:600px; background-color:blue;'>hi</p>");
}
});

// Creates a route to view the selected aphorism
var Aphorism = Backbone.Router.extend({
    routes: {       
        "saying/:id": "showSaying"
    },
    showSaying: function (id) {
        var aphorism_view = new AphorismView();
        alert('Saying id ' + id + '.');
  }
});

//establishes the router
appRouter = new Aphorism;

//Sets up backbone
Meteor.startup(function () {
    filepicker.setKey("AerIOvsmAQRGaNdEv0judz");
    filepicker.constructWidget(document.getElementById('attachment'));
    Backbone.history.start({pushState: true});
});
like image 309
squeezemylime Avatar asked Jan 26 '13 21:01

squeezemylime


2 Answers

Your issue doesn't seem like a Backbone.js issue at all.

Have you tried putting a console.log statement inside the startup() callback to verify that it's actually being called in all cases? If not, then that's between you and Meteor.

like image 111
philfreo Avatar answered Oct 13 '22 00:10

philfreo


have you tried waiting for the DOM to be ready? eg: $( Backbone.history.start )

like image 31
p3drosola Avatar answered Oct 13 '22 01:10

p3drosola