EmberJS: How to transition to a router from a controller's action

Charlie picture Charlie · Jul 19, 2012 · Viewed 18.9k times · Source

I have an action:

{{action create target="controller"}}

which I have targeted to the bound controller (rather than the router) like this:

App.AddBoardController = Ember.Controller.extend
    create: ->
        App.store.createRecord App.Board, {title: @get "boardName"}
        App.store.commit()
        //TODO: Redirect to route

How do I redirect back to a route from the controller action?

Answer

HaoQi Li picture HaoQi Li · Jul 25, 2013

Use transitionToRoute('route') to redirect inside an Ember controller action:

App.AddBoardController = Ember.Controller.extend({
    create: function(){ 
        ...
        //TODO: Redirect to route
        this.transitionToRoute('route_name');
    }
...