Route not fired when using setLocation

72 views
Skip to first unread message

Luis Abreu

unread,
Oct 9, 2013, 5:51:48 AM10/9/13
to sam...@googlegroups.com
Hello guys.

I've decided to use sammy for routing on the client side. Currently, my setup is really simple and looks like this:

var app = $.sammy("#mainContent", function () {
            
            this.get("#/", function(context) {
                //default route
                if (!self.tecnico) {
                    self.navigate("login");
                    return;
                }
                //load default
                self.navigate("main");
            });

            this.get("#/login", function (context) {
                self.loadHtmlFor("login");
            });

            this.get("#/main", function(context) {
                self.loadHtmlFor("main");
            });
            //don't mess with my forms
            this._checkFormSubmission = function(frm) {
                return false;
            };
        });

After searching the web, it seems like I need to set the _checkFormSubmission in order for it to ignore form submissions. I'm doing this because I'm using knockout for binding my objects and intercepting form submissions. 

My problem is that my routes are nout being "picked up" by sammy. For instace, my page initially loads a login form and after the user authenticates herself, I'm trying to redirect it to main with code like this:

self.navigate = function(id) {
            var url = "#/" + self.views[id].propName; /
            window.setTimeout(function() {
                    app.setLocation(url);
                },
                100);
        };

the browser changes the path (http://mysite.pt/demo#/main), but my #/main route function is not called and that means that the HTML for the page is not replaced. Looking at the code, it seems like sammy's location-changed event is being triggered, but the truth is that my route is not called.

What am I missing?

thanks.
Luis


Pushker Yadav

unread,
Feb 4, 2014, 12:40:56 AM2/4/14
to sam...@googlegroups.com
Why you are using setTimeout for setting the location 
Reply all
Reply to author
Forward
0 new messages