Answer the question
In order to leave comments, you need to log in
Backbone and links. How to make it work?
There are: backbone , jquery , require ,underscore
Loads all require. It loads like this: all libraries, models, views and router.js are loaded into app.js and Router.init is made
Respectively
: this is router.js.
define([
'backbone'
], function(Backbone){
console.log(Backbone);
var AppRouter = Backbone.Router.extend({
routes: {
// Define some URL routes
//'':'defaultAction',
//'*actions': 'defaultAction',
'*path': 'defaultAction',
'/projects': 'showProjects',
'projects': 'showProjects',
'/users': 'showUsers'
},
defaultAction: function() {
console.log('index route');
},
showProjects: function()
{
console.log('showProjects');
}
});
var initialize = function(){
console.log('Router.init');
var app_router = new AppRouter;
};
return {
initialize: initialize
};
});
App.init
Router.init
index route
console.log('App.init');
console.log(Views);
Router.initialize();
Views.initialize();
Backbone.history.start({pushState:true, root: "/app111/"});
Answer the question
In order to leave comments, you need to log in
The route '*path': 'defaultAction'
must be the latest. When processing a route, the router goes through the hash with routes and looks for the one that suits it. In your case, the router will always stop on the default route '*path': 'defaultAction'
.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question