在meteor中不能返回到默认模板

Cannot go back to default templates in meteor

本文关键字:默认 返回 meteor 不能      更新时间:2023-09-26

所以我在一个html页面中使用4个模板。模板1是默认模板,当你进入这个html页面时,你应该看到它。

然而,当我浏览其他模板和其他html页面后,当我回到这个页面时,它会显示我离开该页面时所处的模板,而不是默认模板。

HTML:

<template name = "Page1">
  <div class = "events">
    {{>Template.dynamic template=selector}}
  </div>
</template>
<template name = "template1">...</template>
<template name = "template2">...</template>
<template name = "template3">...</template>
<template name = "template4">...</template>
Javascript:

if(Meteor.isClient) {
  Session.setDefault("selector","eventDetailPage");
  Template.showEvent.helpers ({
    selector: function () {
      return Session.get("selector");
    }
  });
  Template.showEvent.events ({
   'click #temp2': function(){
        Session.set('selector’,'template2')
    }
  });
  ...template 2, 3, 4...
}

Session.setDefault("selector","eventDetailPage");可能是您用来跟踪哪些template1/template2/…呈现。它只在web浏览器初始化时被调用。

如果您想在返回page1时返回默认页面,那么您将需要这样的设置。

Template.Page1.onRendered(function() {
    `Session.set("selector","template1");`
})