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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With