问题描述
我正在使用Meteor iron:router.
I am using Meteor iron:router.
我有一个名为"multi"的模板.因此,每当我具有'/multi'或'/multi/BSC123'之类的路径时,我都希望呈现"multi".
I have a template called by the name 'multi'.So whenever I have paths like '/multi' or '/multi/BSC123' , I want 'multi' to be rendered.
到目前为止,我已经使用了像这样的数组方法
So far I have used an array approach like this
Router.route('multi',{
path:['/multi','/multi/:_id']
});
这很好.但是,当我使用这种方法时,没有显示带有指向"multi"模板的href链接的左侧导航栏.因此,除了上述方法之外,任何人都可以建议我其他解决方案,在该解决方案中,我可以呈现两条路径和相同的模板,并且如果存在,我也应该获得"id".
This works fine. But when I use this approach, my left nav bar which has a href link to 'multi' template is not shown. So apart from the above approach, can anyone suggest me other solution where I can have two paths and same template rendered and I should get the "id" too if present.
推荐答案
在路由器js文件中,只需创建两条呈现相同模板的路由:
In your router js file, just create two routes that render the same template:
Router.route('/multi', function () {
this.render('multi');
});
Router.route('/multi/:_id', function () {
this.render('multi', {
data: {
routeid: this.params._id
}
});
});
在您的多模板中:
<template name="multi">
Path: {{pathFor 'multi'}}<br />
ID: {{routeid}}<br />
</template>
现在,如果您访问/multi
,则路径将显示为多"且ID为空.如果您访问/multi/BSC123
,则路径显示为"multi",并且ID为BSC123.
Now if you access /multi
the Path shows up as 'multi' and the ID is empty. If you access /multi/BSC123
the Path shows up as 'multi' and the ID is BSC123.
这篇关于铁路由器具有多个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!