Nic*_* AD 4 javascript ecmascript-6 aurelia aurelia-router
我试着按照这个关于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;
}
}
Run Code Online (Sandbox Code Playgroud)
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>
Run Code Online (Sandbox Code Playgroud)
据我所知,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/sculpture-navigation
| 归档时间: |
|
| 查看次数: |
1117 次 |
| 最近记录: |