javascriptmvcuri-fragment

JavascriptMVC: how do I invoke the Controller's history methods?


JMVC has a History plugin that lets you interact the URL's hash fragment. For example, you can change the #hash part of the URL to make certain actions inside your app bookmarkable, and allow people to navigate using the browser's back button.

Unfortunately, I'm not having much luck using it.

The following code creates a JMVC controller that tries to set the browser URL to something like example.com/myApp#controller/someController. However, nothing happens because the redirectTo() method that the History plugin says it defines, is undefined. I've also tried History.redirectTo().

steal.plugins("jquery/controller/history");
$.Controller.extend('MyControllerWithHistory', {}
{
'.item click': function( el ){
   redirectTo({controller:'someController'});
}
});

What am I doing wrong?

Thanks!


Solution

  • Have you tried this.redirectTo():

    steal.plugins("jquery/controller/history");
    $.Controller.extend('MyControllerWithHistory', {},
    {
    '.item click': function( el ){
        this.redirectTo({controller:'someController'});
    }
    });
    

    By including the history plugin you are adding methods such as redirectTo to $.Controller.