clickify.js intercepts all internal links and passes them to Backbone History/Router
<!-- jQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<!-- backbone.js -->
<script src="/path/to/backbone.js"></script>
<!-- clickify.js -->
<script src="https://raw.github.com/gist/3014727/clickify.js"></script>
Hashbang'd links <a href='http://<site>/#!/whatever'>8====></a> suck. They're ugly, bad for search engines and worse, you end up with a real URL and a hashbang'd URL that both reference the same content on the server.
clickify.js simplifies your single-page web application by allowing non-hash'd URLs with Backbone Router. Use normal links throughout your application, clickify.js will intercept them for use in your single-page app.
This leads to a seamless single-page app experience for users with modern browsers, and standard links for those without (and bots). Best of all, you don't have two links for each piece of content (good for bookmarks, sharing, pagerank, etc)
For nodejs/expressjs users, clickify.js allows you to match your backbone and express routes. Perfect if you plan on rendering the initial page request server-side and all subsequent requests via ajax.
clickify.js creates an event handler on all internal (relative url or same root-url) links. Apply it to any jQuery element, or the entire document body. Remember to apply clickify to any new elements that get inserted to the DOM.
Add class="no-click" to any anchor tags clickify should skip.
$(function() { // DOM ready
// Create a router to handle our URL changes
var SimpleRouter = Backbone.Router.extend({
routes: {
'posts/:id': 'post',
'*notFound': 'notFound' // catch-all for undefined routes
},
post: function(id) {
...
},
notFound: function() {
...
}
});
new SimpleRouter;
Backbone.history.start({ pushState: true }); // Start tracking history
$(document.body).clickify(); // Add click handlers to all internal links
});
How about reloading page? I get 404 error when I reloading page whith the posts/:id link.