Search code examples
javascriptsammy.js

How to pass logout url to server


I have a simple Sammy.js app, as shown below:

Sammy(function () {
        this.get('#/project/:projectId', function () {
            // REST load content into div
        });

        this.get('#/', function () {
            // Load blank div
        });

        this.get('', function () {
            this.app.runRoute('get', '#/');
        });
    }).run();

This bit of code runs pretty well, and either loads up content via restful methods or shows a blank div. However my application has a MVC structure and I need to go to http://localhost/logout to ensure the app logs the user out and kills the session.

However any html links I have in my app that point to the logout url, do not get called. The URL bar shows the logout URL but , the logout action does not happen.

I can capture the link url using sammy, like so:

this.get('logout', function () {
                // What should happen here?
            });

But I am not sure how to get sammy to actually call this url. I have tried this.refresh() and this.get('/logout') but neither work as expected.


Solution

  • The bit of code that actually worked for me, as horrible as it looks is the standard document.location.href:

    var sammy = Sammy(function () {
                this.get('#/project/:projectId', function () {
                    // does some stuff with knockout.js
                });
    
                this.get('#/', function () {
                    // does some stuff with knockout.js
                });
    
                this.get('/logout', function () {
                    document.location.href = './logout';
                });
    
                this.get('', function () {
                    location.hash = '/';
                });
            });