Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to execute a function every time the app enters a given route in ember-js

Tags:

ember.js

Suppose I have got a given ember application

App = Ember.Application.create()

A router

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

How do I execute a function each time whenever the application enters a given /:post_id ?

like image 715
Jay Kanakiya Avatar asked Mar 24 '23 16:03

Jay Kanakiya


1 Answers

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

The activate hook is called on the route every time the route is activated.

Example:

App.PostRoute = Ember.Route.extend({
  activate: function() {
    doSomething();
  }
});
like image 181
Sebastian Seilund Avatar answered Apr 28 '23 14:04

Sebastian Seilund