Backbone: Actualizar la ruta actual
Noté que el método de navegación del enrutador de red troncal no volverá a cargar la ruta actual.
Por ejemplo, la ruta actual es/view1
y tu llamasrouter.navigate('view1',{trigger:true});
. No volverá a activar el evento de ruta.
Aquí está el código que pruebo:
<html>
<head>
<title>Testing123</title>
<script src="http://code.jquery.com/jquery.min.js" type="text/javascript"></script>
<script src="http://underscorejs.org/underscore-min.js" type="text/javascript"></script>
<script src="http://backbonejs.org/backbone-min.js" type="text/javascript"></script>
<style type="text/css" media="screen">
#box{
width:400px;
height:400px;
background-color:red;
}
</style>
</head>
<body>
<button id='view1'>view1</button>
<button id='view2'>view2</button>
<br/>
<div id='box'>
</div>
<script type="text/javascript" charset="utf-8" async defer>
var SystemRouter = Backbone.Router.extend({
routes: {
"view1":"view1",
"view2":"view2"
},
view1: function() {
console.log('view1');
},
view2: function() {
console.log('view2');
}
});
var sys = new SystemRouter();
Backbone.history.start({pushState: true, root: "/test/routing.html#/"});
sys.navigate('view1');
$('#view1').click(function(){
sys.navigate('view1',{trigger:true});
});
$('#view2').click(function(){
sys.navigate('view2',{trigger:true});
});
</script>
</body>
</html>
El código de arriba se cargará/view1
ruta, que imprime 'view1'. Pero si intentas hacer clic en el botón para navegar a/view1
camino, será ignorado.
Mi pregunta es: ¿Cómo llamo al evento de ruta si es la misma que la ruta actual?