Search code examples
ember.jsember-old-router

How to specify action handler in router?


http://jsfiddle.net/pauldechov/u4naE/

App.Router = Em.Router.extend({
enableLogging: true,

root: Em.Route.extend({

    index: Em.Route.extend({
        route: '/',
        connectOutlets: function(router) {
            router.get('applicationController').connectOutlet('application');
        }
    }),

    // why does this work?
    goHome: Em.Route.transitionTo('home'),

    // ...but not this? Am I missing something?
    goHome2: function(router, context) {
        router.transitionTo('home', context);
    },
    home: Em.Route.extend({
        route: 'home'
    })
})
});

I get an error saying: "You must specify a target state for event 'goHome2' in order to link to it in the current state 'root.index'."

How do I define a handler here, so I can return false and stop propagation, for example? Should I actually be doing this in the view, and how would that be done?

Thank you.


Solution

  • Ok, I think I've found it. When using href="true", you have to specify that your function goHome2 is an eventTransition. see http://jsfiddle.net/Sly7/u4naE/2/