2017-02-24 99 views
2

不確定我是很新的Aurelia路上,只是嘗試應用導航到我的project.Though我進口奧裏利亞路由器還是它說RouterConfiguration和路由器在構造RouterConfiguration和路由器在奧裏利亞

import {Todo} from './ToDo/todo'; 
import {RouterConfiguration, Router} from 'aurelia-router'; 


export class App { 
    heading = "Todos"; 
    todos: Todo[] = []; 
    todoDescription = ''; 
    router :any; 
    list: any[]; 

    constructor(RouterConfiguration: RouterConfiguration, Router: Router) { 

     this.todos = []; 
     this.configureRouter(RouterConfiguration, Router); 
     //console.log("klist", this.list); 
    } 

    //config.map() adds route(s) to the router. Although only route, name, 
    //moduleId, href and nav are shown above there are other properties that can be included in a route. 
    //The class name for each route is 
    configureRouter(config: RouterConfiguration, router: Router): void { 
     this.router = router; 
     config.title = 'Aurelia'; 
     config.map([ 
      { route: '', name: 'home', moduleId: 'home/home', nav: true, title: 'Home' }, 
      { route: 'users', name: 'users', moduleId: './Friends/Friends', nav: true }, 
      //{ route: 'users/:id/detail', name: 'userDetail', moduleId: 'users/detail' }, 
      //{ route: 'files/*path', name: 'files', moduleId: 'files/index', href: '#files', nav: 0 } 
     ]); 
    } 

    addTodo() { 
     if (this.todoDescription) { 
      this.todos.push(new Todo(this.todoDescription)); 
      // this.todoDescription = ''; 
     } 
    } 

} 

回答

3

是不確定按照慣例,Aurelia在初始類中查找加載(App)configureRouter()函數並執行它。這意味着,你不必在構造函數中注入任何東西。

看起來你只是添加了太多。我想你的固定樣本似乎是爲消除一些東西,像這樣一樣簡單:

import { Todo } from './ToDo/todo'; 
import { RouterConfiguration, Router } from 'aurelia-router'; 

export class App { 
    heading = "Todos"; 
    todos: Todo[] = []; 
    todoDescription = ''; 
    list: any[]; 

    constructor() { 
     // note: removed routing here entirely (you don't need it) 
     // also, you've already declared this.todos above, so no need to do it here again 
    } 

    configureRouter(config : RouterConfiguration, router : Router): void { 
     this.router = router; 
     config.title = 'Aurelia'; 
     config.map([ 
      { route: '', name: 'home', moduleId: 'home/home', nav: true, title: 'Home' }, 
      { route: 'users', name: 'users', moduleId: './Friends/Friends', nav: true } 
     ]); 
    } 

    addTodo() { 
     // removed this for brevity 
    } 

} 

這應該可以解決的路由器和RouteConfiguration你的「未定義」的錯誤。另外請注意,不要忘記將<router-view>添加到您的html模板中。否則,你會得到沒有錯誤,但該意見也不會顯示出來:

<template> 
    <div class="content"> 
     <router-view></router-view> 
    </div> 
</template> 

這個偉大的文檔可在Aurelia Docs - Routing找到。

+0

謝謝@ashley,它幫助 – Heshan

+0

@ashley是它必須添加到所有模板或添加到app.html將做到這一點? – Heshan