javascript - Aurelia: During a Router's Pipeline Step, how do I bind a variable to that router? -


i'd pass user, found during authorizestep either app class , home module.

here's have:

export class app {     configurerouter(config, router) {         config.addpipelinestep('authorize', authorizestep);          config.map([             {route: ['', ':filter'], name: "", moduleid: 'welcome'}             {route: 'home', name: "home", moduleid: 'home' auth:true}         ]);         this.router = router;     } }  class authorizestep {     run(routingcontext, next) {         if (routingcontext.nextinstructions.some(i => i.config.auth)) {             this.client.get('auth/login')                 .then(response => {                     this.user = response.content;                 });         }         return next();     } } 

in app created class called authcontext currentuser property. can inject in constructor authorizestep , inject in other models need it. like...

import {authcontext} './auth-context';  export class app {     static inject() { return [authcontext];}      constructor(authcontext){         this.authcontext = authcontext;     }      configurerouter(config, router) {          config.addpipelinestep('authorize', authorizestep);           config.map([             {route: ['', ':filter'], name: "", moduleid: 'welcome'}             {route: 'home', name: "home", moduleid: 'home' auth:true}         ]);         this.router = router;     } }  class authorizestep {     static inject() { return [authcontext];}      constructor(authcontext){         this.authcontext = authcontext;     }     run(routingcontext, next) {         if (routingcontext.nextinstructions.some(i => i.config.auth)) {             this.client.get('auth/login')                 .then(response => {                     this.authcontext.user = response.content;                 });         }         return next();     } } 

Comments