Simile a Django {{ url }}
, esiste un metodo o un modo per invertire un percorso particolare passandogli un nome e variabili.Invertire una rotta in Backbone js
// example Router
var router = Backbone.Router.extend({
routes: {
'!/user/:user_id': 'editUserAction',
'!/': 'homeAction'
},
editUserAction(user_id) {
// edit user view
},
homeAction() {
// home view
}
});
Alcuni metodo come
router.reverse('editUserAction', '5');
sarebbe tornato l'hash: !/user/5
router.reverse('homeAction');
sarebbe tornato l'hash: !/
Se devi scrivere un hack, incapsulare esso. – Leopd