[英]Aurelia compose element view model, configureRouter not being called
[英]Aurelia 1.0 routing configureRouter never called
我试着按照这个关于aurelia.io路由的一些教程,如http://www.tutorialspoint.com/aurelia/index.htm
我在我的App类中实现了一个configureRouter方法,但它从未调用过
app.js
export class App {
constructor()
{
console.log("app");
}
configureRouter(config, router){
console.log("configureRouter");
config.title = 'Aurelia';
config.map([
{ route: ['','home'], name: 'home',
moduleId: './components/home/home', nav: true, title:'Home' },
{ route: 'about', name: 'about',
moduleId: './components/about/about', nav: true, title:'About' }
]);
this.router = router;
}
}
app.html
<template>
<nav>
<ul>
<li repeat.for = "row of router.navigation">
<a href.bind = "row.href">${row.title}</a>
</li>
</ul>
</nav>
<router-view></router-view>
</template>
据我所知,app.js中的configureRouter方法应该在模板中检测到路由器视图时自动调用,但事实并非如此(我在chrome控制台中没有出现任何错误)
有任何想法吗?
我遇到了类似的问题,但事实证明,如果模板中没有<router-view></router-view>
,则永远不会调用configureRouter方法。 即使您找到了解决方案,但也许其他人也可以在此解决方案中找到解脱
资料来源: https : //www.niclassahlin.com/2016/03/13/aurelia-router-configuration-caveat/
没有阅读教程,但它似乎在我的机器上工作,可能是你的index.html没有正确设置的东西?
请参阅此处以获取代码的工作示例(使用chrome): https : //gist.run/?id = 49f3aa8ac6cb72f2efc22c3073bc42d8
这也不适用于您的机器吗?
顺便说一句。 结帐Aurelia骷髅,它们是一个简单的起点https://github.com/aurelia/skeleton-navigation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.