Aurelia 无法获取“的”行;路由器导航“;
虽然我对奥雷莉亚还不熟悉,但我真的很喜欢奥雷莉亚。我已经阅读了Aurelia的“入门”部分,并对配置路由器做了一些阅读。具体地说,我把它作为我理解的基础 我遵循正常惯例(app.ts、app.html和navigation.html)。我无法获得“repeat.for”来迭代router.navigation中的行(在本例中是一行)。我确信我犯了一些基本的错误。但无法找出原因。app.html和navigation.html似乎都在“执行”,在浏览器上同时出现“Aurelia路由器演示”和“不错” 谢谢你的帮助 app.tsAurelia 无法获取“的”行;路由器导航“;,aurelia,Aurelia,虽然我对奥雷莉亚还不熟悉,但我真的很喜欢奥雷莉亚。我已经阅读了Aurelia的“入门”部分,并对配置路由器做了一些阅读。具体地说,我把它作为我理解的基础 我遵循正常惯例(app.ts、app.html和navigation.html)。我无法获得“repeat.for”来迭代router.navigation中的行(在本例中是一行)。我确信我犯了一些基本的错误。但无法找出原因。app.html和navigation.html似乎都在“执行”,在浏览器上同时出现“Aurelia路由器演示”和“不错
import { autoinject } from 'aurelia-framework';
import { RouterConfiguration, Router } from 'aurelia-router';
@autoinject
export class App {
public router: Router;
configureRouter(config: RouterConfiguration, router: Router): void {
this.router = router;
config.title = ' Test ';
config.map( [
{route: ['', 'home'], name: 'home', moduleId: './home', nav: true, title: 'Home'},
]);
}
}
app.html
<template>
<require from="./navigation.html"> </require>
<h1> Aurelia Router Demo </h1>
<navigation router.bind="router"> </navigation>
<div class="page-host">
<router-view>
</router-view>
</div>
</template>
奥雷利亚路由器演示
--navigation.html
<template bindable="router">
<h2> nice </h2>
<nav>
<ul>
<li repeat.for="row of router.navigation">
<a href.bind="row.href"> ${row.title} </a>
</li>
</ul>
</nav>
</template>
美好的
-
乍一看,我没有发现任何错误。尝试使用compose
而不是绑定路由器,以查看其是否有效compose
没有指定的视图模型
属性,使用消费者的视图模型,消除了通过数据绑定传递路由器的必要性。请注意,当需要扩展名为.html
的自定义元素时,Aurelia会自动为其生成视图模型
基本上,使用compose
而不是navigation
:
app.html
<template>
<h1> Aurelia Router Demo </h1>
<compose view="./navigation.html"> </compose>
<div class="page-host">
<router-view>
</router-view>
</div>
</template>
<template>
<h2> nice </h2>
<nav>
<ul>
<li repeat.for="row of router.navigation">
<a href.bind="row.href"> ${row.title} </a>
</li>
</ul>
</nav>
</template>
在我的配置中,将aurelia-routing.min.js作为脚本标记并不起作用。(可能重复发布于) 如果我做了一个构建(au build)并包含vendor.js,那么(repeat.for)就可以了
感谢您的快速回复 为我工作!如果将ul/li放在app.html文件中,是否有效?这就是确切的代码(特别是变量名和文件名的大小写)?您是否碰巧也将路由器注入到类中?只是猜测而已。除此之外,我建议更改导航自定义元素的名称,使其包含破折号。Aurelia允许使用单个单词的自定义元素,但标准不允许,我曾经通过使用nav.html而不是nav-bar.html受到了影响。假设已经有一个nav元素(它在我创建的nav.html中使用)。。。我有点崩溃了浏览器:-)