(SPA) Single page application using pushState with sammy.js

voted: 1
spa pushstate routing html5

How you can mix pushState with sammy.js while writing single page application. Example is written on top of jQuery. Requesting page from your browser via URLs: localhost/ localhost/example localhost/example/test will not reload the page and it will log sammys callback in console.

var app = function () {
    var self = this;
    self.sammyUrls = [
    self.run = function () {
        $(document).on("click", "a", function (e) {
            var $target = $(e.target), url = $target.prop("href");

            history.pushState({}, $target.prop("title"), url);
        $.sammy(function () {
            var sammy = this;
            self.sammyUrls.forEach(function (url) {
                sammy.get(url, function (param) { console.info(url, param); });

var application = new app();
working url: not entered
version: not entered
Leave a Comment:
Characters left:
No comments yet.