How to execute a function every time an application enters a given route in ember-js

Suppose I have a given ember application

App = Ember.Application.create()

Router

 App.Router.map(function() { this.resource("posts", function() { this.resource("post", { path: "/:post_id" }) }); }); 

How to execute a function every time the application enters the given /: post_id?

+4
source share
2 answers

You can implement App.PostRoute to specify your custom behavior for your post route. If you do not, Ember will create this class behind the scenes.

The activate quota is called on the route each time the route is activated.

Example:

 App.PostRoute = Ember.Route.extend({ activate: function() { doSomething(); } }); 
+7
source

Use one of the hooks in the router request life cycle here: http://darthdeus.imtqy.com/blog/2013/02/08/router-request-lifecycle/

0
source

Source: https://habr.com/ru/post/1484874/


All Articles