2016-03-12 17 views
12

Trong app.ts Tôi đang tìm cách điều hướng đến home/contract-view/10 trên một hành động. Cố gắngAurelia router điều hướng & điều hướngToRoute

this.router.navigateToRoute(`home/contract-view`, { id: 10}, { absolute: true }); 

không thành công với Route home/contract-view not be found

Một thử:

this.router.navigate(`#/home/contract-view`, { id: 10}); 

không thành công với Route not found: contract-view(…) Làm thế nào để đạt được điều này? App.ts:

configureRouter(config: RouterConfiguration, router: Router) { 
     config.title = 'Contracts Portal'; 
     config.map([ 
      { route: ['', 'dummy'], name: 'dummy', moduleId: 'dummy', nav: false, title: 'Dummy', settings: { pos: 'left' } }, 
      { route: 'home', name: 'home', moduleId: 'home', nav: true, title: 'Home', settings:{pos: 'left', class: 'home' }, auth: true }, 
     ]); 
     this.router = router;  
    } 

Home.ts:

configureRouter(config: RouterConfiguration, router: Router) { 
     config.map([ 
      { route: ['', 'contract-view/:id'], name: 'contract-view', moduleId: 'contract-view', nav: true, title: 'Contract' }, 
      { route: 'doc-view/:id', name: 'doc-view', href:'doc-view', moduleId: 'doc-view', nav: true, title: 'Document' }, 
     ]); 

     this.router = router; 
     this.router.refreshNavigation(); 
    } 

Trả lời

6

Bạn có router trong 'nhà' cấu hình với contract-view/:id, vì vậy bạn cần this.router.navigate('home/contract-view/10'). Và cố gắng xóa this.router.refreshNavigation() quá

0

Cảm ơn @valichek, Chỉ phải làm cho nó this.router.navigate('/home/contract-view/10') để hoạt động. Thêm / vào lúc bắt đầu tạo sự khác biệt.

25

giải pháp ưu tiên sẽ là sử dụng các tuyến đường được đặt tên mà bạn đã định cấu hình trong bộ định tuyến.

this.router.navigateToRoute('contract-view', {id: 10}); 
+1

Đây là câu trả lời đúng. –

+0

Điều này sẽ không hoạt động với các tuyến đường dành cho trẻ em. –

+0

khá chắc chắn nó hoạt động với các tuyến đường trẻ em – weagle08

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