Meteor:我该如何写这条铁路由器路线?

时间:2015-09-28 22:03:15

标签: meteor iron-router

我正在尝试重写我的Iron Router管理员路由器但是当我点击指向/ admin / home的链接时,我收到以下错误。

我该如何重写这条路线?

Router.route('adminhome', {
      layoutTemplate: 'adminlayout',
      path:'/admin/home',
      template: 'adminarea',
      onBeforeAction: function() {
          if (Meteor.loggingIn()) {
              this.render(this.loadingTemplate);
          } else if(!Roles.userIsInRole(Meteor.user(), ['admin'])) {
              console.log('redirecting');
              this.redirect('/');
          } else {
              this.next();
          }
      }
});

这是我得到的错误:

Exception from Tracker recompute function:
debug.js:41 Error: Expected template rendered with Blaze.render
    at Object.Blaze.remove (view.js:679)
    at DynamicTemplate.destroy (iron_dynamic-template.js:327)
    at null._render (iron_layout.js:400)
    at doRender (view.js:351)
    at view.js:199
    at Function.Template._withTemplateInstanceFunc (template.js:457)
    at view.js:197
    at Object.Blaze._withCurrentView (view.js:538)
    at viewAutorun (view.js:196)
    at Tracker.Computation._compute (tracker.js:323)

这是我更新的代码。问题可能与{{>yield}}行有关。这只是一个猜测。

    Router.route('adminhome', {
      layoutTemplate: 'adminlayout',
      path:'/admin/home',
      template: 'adminarea',

      onBeforeAction: function() {
          if (Meteor.loggingIn()) {
              //this.render(this.loadingTemplate);
              this.render("loadingPage");
          } else if(!Roles.userIsInRole(Meteor.user(), ['admin'])) {
              console.log('redirecting');
              this.redirect('/');
          } else {
              this.next();
          }
      }
});


<template name="adminTemplate">
    {{#if isInRole "admin"}}
        {{> adminarea}}
    {{else}}
        Must be admin to see this...
    {{/if}}
</template>

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

1 个答案:

答案 0 :(得分:1)

在你的代码行中......

this.render(this.loadingTemplate);

...将this.loadingTemplate替换为实际的加载模板名称。

EG。

this.render("LoadingTemplateName");