私は単純なウェブサイト(ブログ/パンフレットウェアと思う)のためにFlow RouterとBlaze Rendererを使用しています。Meteor 1.3の経路変更にテンプレートを再レンダリング
私はFlowRouter.path()
を使用してメニュー要素にリンクを作成しています。これらのリンクがクリックされ、ルート上のaction(
)メソッドが起動されると、URLは予期したとおりに変更されます。しかし、テンプレートはリフレッシュされておらず、テンプレートヘルパーは起動されません。
私/lib/route.jsファイル内のルートは
const about = FlowRouter.group({
prefix: '/about'
});
about.route('/:pageSlug/:subSectionSlug', {
action: (params) => {
console.log('action() fired :' + params.pageSlug + ' :' + params.subSectionSlug);
BlazeLayout.render('applicationLayout', {
main: 'basicPage',
});
},
name: 'pageSubsection',
});
ですその後、私のテンプレートは次のようになります - li
要素にselected
クラスを追加するために、単純なヘルパーで
<template name="applicationLayout">
{{> Template.dynamic template=main}}
</template>
<template name="basicPage">
<div id="pageWrapper">
...
<aside class="leftBar subSectionMenu">
{{> sidebar }}
</aside>
...
</div>
</template>
<template name="sidebar">
<ul class="pageMenu">
{{#each subSections }}
{{> sidebarItem}}
{{/each}}
</ul>
</template>
<template name="sidebarItem">
<a class="sidebarItemAnchor" href="{{ href }}">
<li class="sidebarItem .hoverItem {{#if isSelected }} selected {{/if}}">
{{title}}
<span class="sidebarArrow"></span>
</li>
</a>
</template>
-
Template.sidebarItem.helpers({
href() {
const subSection = this;
const params = {
pageSlug: subSection.pageSlug,
subSectionSlug: subSection.slug,
}
return FlowRouter.path('pageSubsection', params, {});
},
isSelected() {
const slug = FlowRouter.current().params.subSectionSlug;
console.log('running isSelected with ' + slug);
if (this.slug === slug) {
return true;
} else {
return false;
}
}
});
私は、どのように(そしていつ)のtempl atesがレンダリングされます。
ルートが変更されたときにこれらのテンプレートを再レンダリングするには、何が必要ですか?
こんにちは。あなたはそれのための任意の解決策がありますか?私はそれが完全なページを再ロードせずに通常のルート変更のように振る舞います。その他の推奨事項はBlazeLayout.reset()を使っていましたが、基本的には再レンダリングを行いましたが、実際には醜い&悪いと感じています –