Created
April 13, 2014 02:54
-
-
Save leomicheloni/10567065 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type="text/javascript" src="js/vendor/jquery/jquery.js"></script> | |
<script type="text/javascript" src="js/vendor/underscore/underscore.js"></script> | |
<script type="text/javascript" src="js/vendor/backbone/backbone.js"></script> | |
<script type="text/javascript"> | |
//creamos una clase Router extendiendo la clase base de Backbonejs | |
var Router = Backbone.Router.extend({ | |
//definimos las rutas | |
routes:{ | |
"": "home", // la url por defecto va a llamar a la función home | |
"accion1": "funcion1", //la url #accion1 va a llamar a funcion1 | |
"accion1/:parametro1": "funcion2" //la url #accion1 va a llamar a funcion1 | |
}, | |
home: function(){ | |
console.log("estamos en casa"); | |
}, | |
funcion1: function(){ | |
console.log("la acción 1 ha sido llamada"); | |
}, | |
funcion2: function(parametro1){ | |
console.log("se llama a la acción con el valor de parámetro: " + parametro1); | |
} | |
}); | |
//creamos un router | |
var router = new Router(); | |
//iniciamos el motor de navegación | |
Backbone.history.start(); | |
</script> | |
</head> | |
<body> | |
<a href="#accion1">Ir a la acción 1</a> </br> | |
<a href="#accion1/valor1">Ir a la acción 1 y pasar un parámetro</a> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment