Skip to content

Instantly share code, notes, and snippets.

@pvanneau
Last active December 17, 2015 10:49
Show Gist options
  • Save pvanneau/5598118 to your computer and use it in GitHub Desktop.
Save pvanneau/5598118 to your computer and use it in GitHub Desktop.
Routing tools for webapp (like Backbone)
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) index.html [L]
</ifModule>
define([
'jquery',
], function($)
{
var Helpers = {};
Helpers.preventClick = function(appRouter)
{
$(document).on("click", "a[href^='/']", function(event)
{
var href, passThrough, url, rel;
href = $(event.currentTarget).attr('href');
rel = $(event.currentTarget).attr('rel');
if (
(rel !== "external") &&
!event.altKey &&
!event.ctrlKey &&
!event.metaKey &&
!event.shiftKey)
{
event.preventDefault();
url = href.replace(/^\//, '').replace('\#\!\/', '');
appRouter.navigate(url, {
trigger: true
});
return false;
}
});
}
return Helpers;
});
var express = require('express'),
app = express();
app.use(express.static(__dirname + '/'));
app.get(/^(.*)$/, function(req, res) {
res.sendfile(__dirname + '/index.html');
});
app.listen(process.env.PORT || 8080);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment