Iron router with multiple parts
I am using Meteor iron: router.
I have a template called "multi". So when I have paths like "/ multi" or "/ multi / BSC123" I want "multi" to be displayed.
So far I have used a similar array method
Router.route('multi',{
path:['/multi','/multi/:_id']
});
This works great. But when I use this approach, my left navbar, which has an href to the "multi" template, is not displayed. So besides the above approach, someone can suggest me another solution where I can have two paths and the same template and I should get the "id" if there is one.
In the ros js file, just create two routes that display the same pattern:
Router.route('/multi', function () {
this.render('multi');
});
Router.route('/multi/:_id', function () {
this.render('multi', {
data: {
routeid: this.params._id
}
});
});
In your multi template:
<template name="multi">
Path: {{pathFor 'multi'}}<br />
ID: {{routeid}}<br />
</template>
Now, if you access /multi
, the path is displayed as "multi" and the id is empty. When accessing, the /multi/BSC123
path is displayed as "multi" and the ID is BSC123.
source to share