Meteor - 如何在Template事件函数内正确路由

时间:2015-01-09 06:36:05

标签: javascript templates events meteor iron-router

我有一个基本模板:

<template name="ApplicationLayout">
    {{> yield}}
</template>

我使用Iron Router将模板路由到它中,如下所示:

Router.configure({
  layoutTemplate: 'ApplicationLayout',
  notFoundTemplate: 'home'
});
Router.route('/', function () {
  this.render('home');
});

每当有人到达网站时,他们将始终显示agegate模板。单击提交按钮后,我想更改为其他页面(主页)。

Template.agegate.events({
    "click #submit": function (event) {
        this.render('home');
    }
});

路由实际上有效(我到达了所需的页面),但它会抛出一个错误:

Uncaught TypeError: undefined is not a function

我假设这是因为this中的this.render('home')引用了当前模板,而需要引用父模板(ApplicationLayout模板)。但是,我不知道该怎么做,或者这甚至是相关的。

那么,如何在模板事件函数中正确路由?

1 个答案:

答案 0 :(得分:6)

尝试使用Router.go('/'),这应该足够了