我试图从一个儿童路线导航到另一个儿童路线,但我不断得到Route not found
。我的主要问题:如何浏览子视图?Aurelia:儿童路线之间的导航
下面是代码,下面还会有其他问题。
应用模式 - 视图 App类:
export class App {
configureRouter(config, router) {
config.title = 'My Site';
config.map([
{ route: ['','job-view'], name: 'jobView', moduleId: './job-view', nav: true, title:'Jobs'},
{ route: ['services'], name: 'services', moduleId: './services', nav: true, title:'Services'}
]);
this.router = router;
this.router.refreshNavigation();
}
}
Q.2:为什么我们需要保存router
这里,如果它总是从访问aurelia-router
?
应用页面:
<template>
<require from='./nav-bar'></require>
<nav-bar router.bind="router"></nav-bar>
<div class="container">
<router-view></router-view>
</div>
</template>
好了,现在我们已经定义了我们的根页面视图和导航,让我们定义job-view
MV。
工作视图类:
export class JobView {
configureRouter(config, router) {
config.map([
{ route: ['','jobs'], name: 'jobs', moduleId: './jobs', nav: false, title:'Jobs', settings:{icon:'glyphicon glyphicon-align-justify'} },
{ route: ['job/:id'], name: 'job', moduleId: './job', nav: false, title:'Job Details'}
]);
this.router = router; //WHY SAVE THIS?
this.router.refreshNavigation();
}
}
工作视图页:
<template>
<router-view></router-view>
</template>
现在,这里是孩子的意见。我的假设是,发生的路由应该是相对于job-view
。这就是我想要的,理想的。
工作类(为简洁移除一串代码):
import {Router} from 'aurelia-router';
@inject(Router)
export class Jobs {
constructor(router) {
this.router = router;
}
toJob(id) {
// this.router.navigateToRoute("job", {id:id}); // ERROR - ROUTE NOT FOUND
this.router.navigate("#/job-view/job/".concat(id)); // THIS WORKS
}
}
Q.3:我看到二者router.navigateToRoute
和router.navigate
引用,但没有指示时,既可以使用或者有什么区别,并且文件看不到解释。应该使用哪个? Docs
职位页: 细则jobs.html
是无关紧要的,所以这里没有列出。
最后,job
观点:
作业类: 相关job.js
没有,所以不上市代码。最多我可以执行导航回到jobs
,但这在页面下方处理。
招聘页:
<!-- a bunch of html //-->
<!-- HOW TO USE ROUTER IN HTML, NOT BELOW URL HREF? //-->
<a href="#/jobs">Print Jobs</a>
<!-- a bunch of html //-->
Q.4:同样,我想路由到相对的,即使是在HTML页面。以上将不起作用,所以我应该使用什么?
在类似的问题中有一个proposed answer,但注入job-view
到job
和使用job-view
的保存的路由器也没有工作。
顺便说一下,如果我手动导航到http://localhost:3000/#/job-view/job/3
页面加载正常,所以这是明确的路由器。
注意mod: 类似的问题在How to access child router in Aurelia?被询问,但它没有得到解决方案的回答。
'route-href'不是我以前见过的。有趣。是否有文档?我会尝试,当我有机会。我遇到的问题是我的电话'this.router.navigateToRoute(“job”,{id:id});'。我会更新这个问题来反映这一点。 –
抱歉,因为很长的时间没有回复你。 route-href位于“生成路由URL”下的备忘单中http://aurelia.io/docs.html#/aurelia/framework/1.0.0-beta.1.1.2/doc/article/cheat-sheet – Brandon
'this.router.navigateToRoute('workDetail',{slug:'slug'});'(或者它应该是'this.router.navigate('workDetail',{slug:'slug'});')工作'workDetail.js'(假设'workDetail'上的'configureRouter'类捕获''router')? –