It could be useful to have a default view for unmapped route, using a default route.
The idea is to have an error page for not mapped routes. This way, the application informs the user that he clicked a dead link, instead of just silently updating the hash in the browser.
Default router :
var layout = require('../views/layout');
module.exports = Fmk.Helpers.Router.extend({
routes: {
'*path': 'defaultRoute'
},
defaultRoute: function () {
var View = require('../views/technique/routeNotFound/routeNotFoundStatic');
var model = new Backbone.Model({route: Backbone.history.fragment});
var view = new View({model: model});
layout.content.show(view);
}
});
We use the *splat joker to select all unmapped routes.
Beware, if there is several routers, the default router must be the first one to be initialized (and not the last one as one might think).
//Dependencies.
var DefaultRouter = require('./defaultRouter');
var HomeRouter = require("./homeRouter");
var AffaireRouter = require('./affaireRouter');
/*Router instanciation.*/
module.exports = {
routerList: [
new DefaultRouter(),
new HomeRouter(),
new AffaireRouter()
]
};
The view simply displayed the unmapped route :
<div class="techError">
<h4><i class="fa fa-exclamation-triangle"></i> Route inexistante : {{route}}</h4>
</div>
It could be useful to have a default view for unmapped route, using a default route.
The idea is to have an error page for not mapped routes. This way, the application informs the user that he clicked a dead link, instead of just silently updating the hash in the browser.
Default router :
We use the
*splatjoker to select all unmapped routes.Beware, if there is several routers, the default router must be the first one to be initialized (and not the last one as one might think).
The view simply displayed the unmapped route :