javascript - Fire route/controller hooks every time url changes in ember app -


i have 2 routes in app backed models have access control logic on rails side. when first load application, they've got isunlocked property check after model loads. if property not unlocked, route should redirect.

so if router like:

this.route('thing', { path: 'thing/:thing_id' }, function() {   this.route('resource', { path: 'resource/:resource_id' }); }); 

and "resource" route extends this:

import authenticatedroute 'doki/routes/authenticated';  export default authenticatedroute.extend({    requiredean: false,    activate() {     this._super();     this.checkaccess();   },    aftermodel() {     this._super();     this.checkaccess();   },    resetcontroller() {     this._super();     this.checkaccess();   },    checkaccess() {     // here i'll check model's isunlocked property ,      // redirect if it's false or not set     console.log('checkaccess');   }  }); 

when enter /thing/1/resource/1, model resource=1 loaded thingresourceroute, if resource=2 loaded in store, if click on /thing/1/resource/2, activate doesn't fire, setupcontroller doesn't fire, etc, i'm not sure checkaccess() test.

what's best place check isunlocked property whenever url changes, because "activate", "resetcontroller", et al, don't fire when url changes same route different item has different isunlocked property.

is there hook can implement called? putting access check in rendertemplate seems it'd work, doesn't seem right place.

should invalidate model after updating model via api call? if set isunlocked true locally (and don't persist model via api), add check in route/controller chain check every time tries "access" model?

looks didtransition event fires every time url entered—even when model loaded, controller has been setup, , hooks have fired—so i'm going check model in didtransition:

actions: {     didtransition: function() {       console.log('-- transitioned into', this.routename, this.get('controller.model'));     } } 

Comments

Popular posts from this blog

node.js - Using Node without global install -

How to access a php class file from PHPFox framework into javascript code written in simple HTML file? -

java - Null response to php query in android, even though php works properly -