2016-05-30 73 views
0

我在应用程序中使用Aurelia的路由机制时遇到问题。我的应用程序目前由3个页面组成。应用程序(主文件),欢迎和表单页面。我能够使用Auth0实现社交登录。我的想法是,当有人从欢迎页面登录时,他们被重定向到表单页面。我已经尝试并通过从aurelia-router导入路由器进行尝试,但始终显示未定义。我仍然掌握了这个令人敬畏的框架,如果有人会告诉我我出错的地方,我将不胜感激。路由器对象始终处于未定义状态

谢谢你的时间家伙。代码如下:

// app.js: 
import {inject} from 'aurelia-framework'; 
import {Router} from 'aurelia-router'; 

@inject(Router) 

export class App { 
    constructor(router) { 
     this.router = router; 
     this.router.configure(config => { 
      config.title = 'My App'; 
      config.map([ 
       {route: ['', 'welcome'], name: 'welcome', moduleId: 'welcome', nav: true, title: 'Welcome'}, 
       {route: ['form', 'form'], name: 'form', moduleId: 'form', nav: false, title: 'Provide your Details'} 
      ]); 
     }); 
     console.log(this.router) // this properly displays the object in the console 
    } 
} 

//welcome.js: 
import {inject} from 'aurelia-framework'; 
import {HttpClient} from 'aurelia-fetch-client'; 
import {Router} from 'aurelia-router'; 

@inject(HttpClient) 
@inject(Router) 

export class Welcome { 
    heading = 'Welcome to my App!'; 
    lock = new Auth0Lock('xxxxxxxxxx', 'xxxxxxxxxx'); 
    isAuthenticated = false; 

    constructor(http, router) { 
     this.http = http; 
     this.router = router; 

     console.log(router) // Shows undefined 
    } 

    login() { 
     // In welcome.html there is a button that succcessfully returns a successful facebook login. This function should navigate the user to the home page using: 
     this.router.navigate('form'); 
     // But this says navigate property is not defined 
    } 

} 

我希望我解释得很好。谢谢您的帮助!

回答

1

我想出了问题所在。我发现我不能使用:

@inject(HttpClient) 
@inject(Router) 

,我不得不用一条线路上使用,如:

@inject(HttpClient, Router) 

现在的作品如预期!谢谢!