Question

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.

Was it helpful?

Solution 2

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 = '/';
            });
        });

OTHER TIPS

I am new on Sammy and I was doing a tutorial when I got the same error. For some reason, get('', function()...) is getting all url that does not match with others get methods, instead to match just with 'empty' url. I solved my problem that way.

I saw that on Sammy homepage: http://sammyjs.org/

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

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

    //remove this 
    //this.get('', function () {
    //    this.app.runRoute('get', '#/');
    //});
// put your initial url inside run
}).run("#/");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top