2016-06-28 19 views

Trả lời

20

Bạn có thể tiêm bộ định tuyến và nhận hướng dẫn hiện tại. Như thế này:

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

Hãy lưu ý rằng 'currentInstruction' vẫn là' null' trong hàm tạo, vì vậy nếu bạn muốn sử dụng nó để ràng buộc, bạn có thể lấy nó trong phương thức 'created' (xem thêm [component vòng đời] (http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/creating-components/3) –

+0

Tôi nhận được dữ liệu của tuyến đường trước đây, bất kỳ ý tưởng nào tại sao ??? – IngoB

+0

Có lẽ vì chế độ xem chưa thay đổi Kiểm tra xem bạn có chức năng 'canDeactivate' là –

Các vấn đề liên quan