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});
});
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.
have you tried waiting for the DOM to be ready? eg: $( Backbone.history.start )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With