1
我有兩個類:應用程序和身份驗證。我的導航是全球資源。我如何使用父路由器的值在子路由器中呈現導航。對不起我的英語不好。謝謝:)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;
}
}