流星 - Router.go() 在传递变量时不 运行

Meteor - Router.go() doesn't run when passed a variable

我有一个我一直重复使用的后退按钮模板:

<template name="btnBack" label="" path="">
    <a href="" data-path="{{path}}" class="btn btn-info btn-small" role="button">
        <span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> {{label}}
    </a>
</template> 

我静态地传递了两个字段,labelpath

我的意图是将静态 path 字段传递给 Iron-Router 以更改呈现的模板。

href 设置为 {{pathFor '{{path}}'}} 无效。 也没有将属性 onclick 定义为 Router.go('{{path}}').

在我的第三次尝试中,我将路径传递给数据属性: data-path="{{path}}"

然后我从模板助手中引用这个属性:

Template.btnBack.events({
  'click a': function(event, template) {
    var path = ''+event.target.dataset.path;
    console.log(path); 
    Router.go(path); 
  }
});

console.log 语句正确运行,并在Google Chrome 的控制台window 中输出静态定义的路径。

Router.go 但是,什么都不做 - 它甚至不会在控制台中为不正确的路径抛出错误。

以下是我如何实例化模板: {{> btnBack label="Back" path="home"}}

我做错了什么?

您可以尝试将 link 设置为

<template name="btnBack" label="" path="">
    <a href="{{ pathFor path }}" class="btn btn-info btn-small" role="button">
        <span class="glyphicon glyphicon-menu-left" aria-hidden="true"></span> {{label}}
    </a>
</template>