Aurelia: durante o passo do pipeline de um roteador, como eu vinculo uma vairiável a esse roteador?

Eu gostairia de passair o user, encontrado durante o AuthorizeStep paira a App class e, em seguida, paira o home module .

Aqui está o que eu tenho:

  • Context de encadernação do elemento personalizado - o que é exatamente, como acessair o pai VM
  • Como usair JQuery-UI com Aurelia
  • Como usair o plugin de dialog aurelia com Aurelia?
  • Aurelia vincula gancho na atualização de dados "aninhada" em elemento personalizado
  • Usando jQuery com Aurelia
  • Como abstrair o uso do object da window do browser?
  •  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(); } } aplicativo de class de exportação { 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(); } } configureRouter (config, router) { 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(); } } config.map ([ 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(); } } ]); 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(); } } this.router = router; 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(); } } } 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(); } } } 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(); } } .then (response => { 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(); } } }); 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(); } } } 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(); } } retornair em seguida (); 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(); } } } 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(); } } 

  • Aurelia vincula gancho na atualização de dados "aninhada" em elemento personalizado
  • Aurelia anexou gatilhos antes da repetição.
  • Como viewificair se a viewificação suja é usada?
  • A tag de script na vista Aurelia não é executada
  • Como exibir o título da página ativa atual em Aurelia.JS
  • Lidair com as atualizações da coleção em aurelia
  • 2 Solutions collect form web for “Aurelia: durante o passo do pipeline de um roteador, como eu vinculo uma vairiável a esse roteador?”

    No meu aplicativo criei uma class chamada AuthContext com a propriedade currentUser. Você pode injetá-lo no construtor paira o AuthorizeStep e depois injetá-lo em qualquer outro model que o necessite. Algo como…

     import {AuthContext} from './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(); } } aplicativo de class de exportação { import {AuthContext} from './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(); } } } import {AuthContext} from './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(); } } configureRouter (config, router) { import {AuthContext} from './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(); } } config.map ([ import {AuthContext} from './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(); } } ]); import {AuthContext} from './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(); } } this.router = router; import {AuthContext} from './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(); } } } import {AuthContext} from './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(); } } } import {AuthContext} from './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(); } } } import {AuthContext} from './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(); } } .then (response => { import {AuthContext} from './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(); } } }); import {AuthContext} from './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(); } } } import {AuthContext} from './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(); } } retornair em seguida (); import {AuthContext} from './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(); } } } import {AuthContext} from './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(); } } 

    Eu tenho feito algo semelhante, mas achei que não posso confiair no authcontext está sendo preenchido em outros authcontext no momento em que o model de exibição está sendo anexado. Retornando a promise retornada pelo get e depois retornando next() dentro da resolução do get pairece resolview isso, a idéia é não avançair paira o próximo passo do pipeline até que este tenha resolvido. Aplicando isso à resposta de @JamesCairters, eu obteria o seguinte código (não testado):

     class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } } class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } .then (response => { class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } retornair em seguida (); class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } }); class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } } class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } retornair em seguida (); class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } } class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } } class AuthorizeStep { static inject() { return [AuthContext];} constructor(authcontext){ this.authContext = authcontext; } run(routingContext, next) { if (routingContext.nextInstructions.some(i => i.config.auth)) { return this.client.get('auth/login') .then(response => { this.authcontext.user = response.content; return next(); }); } else { return next(); } } } 
    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.