2016-05-30 6 views
0

У меня возникли проблемы с использованием механизма маршрутизации Aurelia в моем приложении. В настоящее время мое приложение состоит из 3 страниц. Приложение (основной файл), приветствие и страницы формы. Я смог реализовать Social Login с помощью Auth0. Моя идея заключается в том, что когда кто-то заходит на страницу приветствия, они перенаправляются на страницу формы. Я попытался и попытался импортировать Router с 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) 

Теперь он работает как задумано! Спасибо!

Смежные вопросы