2017-02-24 101 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