使用Aurelia的router-view和viewPorts时,如果发现它们不起作用,可能有以下几个问题和解决方法:
import { Router, RouterConfiguration } from 'aurelia-router';
export class App {
configureRouter(config, router) {
config.title = 'Aurelia';
config.map([
{ route: '', moduleId: './home', name: 'home', title: 'Home' },
{ route: 'about', moduleId: './about', name: 'about', title: 'About' },
]);
this.router = router;
}
}
config.map([
{
route: 'dashboard',
name: 'dashboard',
viewPorts: {
'main': { moduleId: './main' },
'sidebar': { moduleId: './sidebar' },
},
title: 'Dashboard',
},
]);
export class App {
constructor(router) {
this.router = router;
}
async activate() {
await this.router.ensureConfigured();
}
configureRouter(config, router) {
// ...
}
}
通过检查以上问题并根据需要进行调整,你应该能够解决Aurelia的router-view和viewPorts不起作用的问题。