Essentially, I have a mock application with a common header and footer for a specific route. The fact is that I want to be able to go to the main content for this layout when the sub item was damaged.
Example: #products are the main route, and #products /: id is the subitem.
In my controller for this module, I use require.js to grab the view for the #products route and show the fit with the global header and footer as part of these layout areas. I also define the content area that I want to convey when the identifier is included in the route. So, how can I call methods in a view after this new route has been hit? Do I need to cache the current state of the application when the parent route is hit, and then refer to it when the subpath is hit? And would I also need to start browsing when the sub is deleted and the parent route has not been visited by the user?
the router
define(['backbone', 'marionette', 'c_controllers/Controller'], function ( Backbone, Marionette, Controller ) {
'use strict';
var AppRouter = Backbone.Marionette.AppRouter.extend({
appRoutes : {
'product' : 'product',
'product/:id' : 'showPlp'
}
});
return new AppRouter({'controller': Controller});
});
controller
define(["backbone", 'marionette'], function (Backbone, Marionette) {
'use strict';
return {
product : function( id ) {
require(['c_product/product',
'app_views/menu'], function( Product, Menu ) {
APP.menu.show( new Menu() );
APP.page.show( new Product() );
});
}
};
});
View
define([
'backbone', 'marionette', 'app_views/globalNav',
'c_product/productLanding', 'text!productNavTemplate', 'text!productBaseTemplate'], function( Backbone, Marionette, GlobalNav, ProductLanding, ProductNavTemplate, ProductBaseTemplate ) {
var product = Backbone.Marionette.Layout.extend({
id : 'product',
template : _.template( ProductBaseTemplate ),
regions : {
nav : '#globalNav',
content : '#view-content',
footer : '#footer'
},
events : {
},
initialize : function() {
},
onRender : function() {
var Nav = GlobalNav.extend({ template : _.template( ProductNavTemplate )});
this.nav.show( new Nav() );
this.content.show( new ProductLanding() );
}
});
return product;
});