2016-06-28 31 views

risposta

20

È possibile iniettare il router e ottenere le istruzioni correnti. Come questo:

import { inject } from 'aurelia-dependency-injection'; //or framework 
import { Router } from 'aurelia-router'; 

@inject(Router) 
export class MyClass { 

    constructor(router) { 
     this.router = router; 
    } 

    getRoute() { 
    return this.router.currentInstruction.config.name; //name of the route 
    //return this.router.currentInstruction.config.moduleId; //moduleId of the route 
    } 
} 
+5

prega di notare che 'currentInstruction' è ancora' null' nel costruttore, quindi se si desidera utilizzarlo per la rilegatura, si può ottenere nel metodo 'created' (si veda anche la [componente lifecycle] (http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/creating-components/3) –

+0

Sto ottenendo i dati del percorso precedente qui, qualche idea del perché ??? Grazie – IngoB

+0

Probabilmente perché la vista non è ancora cambiata. Controlla se hai una funzione 'canDeactivate' –

Problemi correlati