Skip to content

Instantly share code, notes, and snippets.

@watert
Last active August 29, 2015 14:07
Show Gist options
  • Select an option

  • Save watert/6352ca88f19cde1c6acf to your computer and use it in GitHub Desktop.

Select an option

Save watert/6352ca88f19cde1c6acf to your computer and use it in GitHub Desktop.
Backbone Router Example
<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>
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