I am developing a application using requirejs and backbone, in the index view (index page) i am getting 2 difficulties...
when i use the navigate function like this:
this.navigate("dashBoard/");
it's not works, in case if i use:
Backbone.history.navigate("dashBoard/");
it's working fine. even though in my "routes" i am not getting the function triggered. here is my index view..
define(["singleton","backbone"],function (obj,Backbone) {
window.EDMS = obj || {};
EDMS.index = Backbone.View.extend({
el:$(".loginPage > section"),
events:{
"click #loginBtn" : "enter"
},
initialize:function(){
this.$el.html(this.template());
},
enter:function(e){
e.preventDefault();
var userName = $.trim(this.$el.find("#userName").val()),
password = $.trim(this.$el.find("#password").val());
if(userName && password){
Backbone.history.navigate("dashBoard/"); //only this is works
//this.navigate("dashBoard/") not working.
}else{
return false;
}
}
});
return EDMS.index;
})
But in case of console of "EDMS.routers" - i am getting the methods... how to sync my index view to routers properly.. any help?
my routers.js
define(["singleton","backbone","utils"], function (EDMS,Backbone,utils) {
window.EDMS = window.EDMS || {};
EDMS.routers = Backbone.Router.extend({
routes:{
"":"caller",
"dashBoard/":"dashBoard"
},
initialize:function(){
utils(["index"]);
},
caller:function(){
console.log("i am called");
},
dashBoard:function(){
console.log("welcome to dashBoard");
}
});
return EDMS.routers;
})
my app initializing on require.js
require(["jquery","underscore","backbone","singleton","routers"],function ($,_,Backbone,EDMS,routers) {
EDMS.router = new EDMS.routers();
Backbone.history.start();
});