Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember.js: Call actions of ApplicationRoute from nested route

Let's say I have an ApplicationRoute with an action goBack (as you can see in the comment, I need to handle goBack by myself due to bugs in different mobile browsers):

Mobile.ApplicationRoute = Em.Route.extend
    actions:
        goBack: ->
            # TODO: Remove when iOS 7 fixed their history
            # If there's no route to go back, go to front
            # TODO: Remove when Microsoft fixed their
            # back button in offline mode
            if not (Nn.MobileHelper.isiPhone() or Nn.MobileHelper.isIeMobile()) and @get("router.recentRoute")?
                return window.history.back()

            @get("controller").set("isHitBackButton", true)

            @transitionTo("front").then => @get("controller").set("isHitBackButton", false)

How can I trigger this action from another route? Note that since I need to call @transitionTo, this piece of code must be inside a route.

like image 468
thobens Avatar asked Nov 01 '13 09:11

thobens


1 Answers

actions bubble up to the application route by default! Just use {{action 'goBack'}} in your template, or from code (minus components) call this.send('goBack'). From components you need to wire up the event call a little different and use this.sendAction('internalActionName').

http://emberjs.jsbin.com/ulIhUze/1/edit

like image 199
Kingpin2k Avatar answered Oct 03 '22 08:10

Kingpin2k