1
나는 App과 Auth라는 두 가지 클래스가 있습니다. 내 탐색은 글로벌 리소스입니다. 상위 라우터의 값을 가진 하위 라우터에서 nav를 어떻게 렌더링 할 수 있습니까? 내 영어로 미안해. 감사합니다 :)aurelia 하위 라우터 렌더링 탐색 부모 라우터 설정
export class App {
configureRouter(config, router) {
config.options.pushState = true;
config.options.root = '/'
config.map([
{ route: '', name: 'home', moduleId: './modules/home/home', nav: true, title: 'Home'},
{ route: 'auth', name: 'auth', moduleId: './modules/auth/auth', nav: true, title: 'Auth'}
]);
config.mapUnknownRoutes({moduleId: 'errors/not-found'});
this.router = router;
}
}
export class Auth{
configureRouter(config, router) {
config.map([
{ route: '', redirect: 'login'},
{ route: 'login', name: 'login', moduleId: './login', title: 'Вход' },
{ route: 'register', name: 'register', moduleId: './register', title: 'Регистрация' },
]);
}
}
내 헤더 구성 요소보기는 다음과 같습니다
<li md-waves repeat.for="row of router.navigation" class="${row.isActive ? 'active' : ''}">
<a href.bind="row.href">${row.title}</a>
</li>
내 헤더 구성 요소 클래스는 다음과 같습니다
는import {inject} from 'aurelia-framework';
import {HttpClient, json} from 'aurelia-fetch-client';
import { Router } from "aurelia-router";
@inject(HttpClient, Router)
export class HeaderComponent {
categories = [];
constructor(http, router) {
http
.fetch('categories', {
method: 'get'
})
.then(response => response.json())
.then(data => {
this.categories = data;
})
.catch(error => {
alert.log('Error!');
});
this.router = router;
}
}