Last active
August 29, 2015 14:07
-
-
Save watert/6352ca88f19cde1c6acf to your computer and use it in GitHub Desktop.
Backbone Router Example
This file contains hidden or 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
| <IfModule mod_rewrite.c> | |
| RewriteEngine On | |
| RewriteCond %{REQUEST_FILENAME} !-f | |
| RewriteCond %{REQUEST_FILENAME} !-d | |
| RewriteRule ^(.*)$ index.html?/$1 [L] | |
| </IfModule> | |
| <IfModule !mod_rewrite.c> | |
| ErrorDocument 404 /index.php | |
| </IfModule> |
This file contains hidden or 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
| var DocRouter = Backbone.Router.extend({ | |
| routes:{ | |
| "page/*query":"page", | |
| "*actions":"defaultRoute" | |
| }, | |
| defaultRoute:function(){ | |
| console.log("Routing DefaultRoute"); | |
| }, | |
| page:function(query){ | |
| console.log("Routing Page:"+query); | |
| } | |
| }) | |
| window.docRouter = new DocRouter(); | |
| Backbone.history.start({ | |
| pushState: true, | |
| root: $("base").attr("href") | |
| }); | |
| $("a").click(function(e){ | |
| var isValid = true; | |
| if(isValid){ | |
| docRouter.navigate( $(this).attr("href"),{trigger:true}); | |
| e.preventDefault(); | |
| } | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment