Meteor中的Iron路由器包问题

Iron Router Package issue in Meteor?

本文关键字:问题 包问题 中的 Iron 路由器 Meteor      更新时间:2023-09-26

我需要了解铁路由器包装的用法。我正在使用最新版本的流星。

问题:我正在使用Router.go('hello')

路由器工作正常。但问题是hello模板数据附加到已存在的模板数据

请参阅以下代码:

router.js:

Router.map(function() {
  this.route('home', {path: '/'});
  this.route('hello',{path: 'hello'});
});

hello.html:

<Template name = "hello">
   <h1>This is hello sections</h1>
</Template>

sampleApp.Html:

<head>
  <title>sampleApp</title>
</head>
<body>
  {{> hello1}}
</body>
<template name="hello1">
  <h1>Hello World!</h1>
  {{greeting}}
  <input type="button" value="Click" />
</template>

sample.js

if (Meteor.isClient) {
  Template.hello1.greeting = function () {
    return "Welcome to sampleApp.";
  };
  Template.hello1.events({
    'click input' : function () {
      // template data, if any, is available in 'this'
      if (typeof console !== 'undefined')
        console.log("You pressed the button");
        Router.go('hello');
    }
  });
}
if (Meteor.isServer) {
  Meteor.startup(function () {
    // code to run on server at startup
  });
}

输出显示:

点击按钮前:

Hello World!
Welcome to sampleApp.
**Button Click Me**

点击按钮后:

Hello World!
Welcome to sampleApp.
**Button Click Me**
This is hello sections

这里的问题是Route.go没有转到新页面。那么该怎么办。请给我建议。

提前感谢。

编辑:只需删除部分:<body> {{>hello1}} </body>,它将按照您的意愿工作:)body标记中的内容将始终呈现。