铁路由器不在渲染中渲染模板

时间:2015-01-08 01:07:43

标签: javascript meteor render iron-router

所以我喜欢Meteor,但是Iron Router遇到了一些问题。这次我似乎无法让Iron Router将模板渲染到yield区域。最初一切都很好,但当我点击链接回家({{pathFor ...}}时,URL会发生变化,但视图中没有任何变化。这很奇怪,因为我已经检查过它正在调用路由而我已经明确地编写并测试了this.render('...')以试图强制它渲染我想要的模板(这不起作用)。此外,一旦页面重新加载了更改的URL(即渲染),它就会正确呈现主页)。非常感谢任何帮助。谢谢!

这是router.js(已更新):

Router.configure({
  layoutTemplate: 'layout',
  loadingTemplate: 'loading'
});
//Basic Routes
Router.route('/',function(){
  this.render('main');
},{name:"main"});
Router.route('/Board',function(){
  this.render('board');
},{name:"board"});
Router.route('/Board/:chat',function(){
  this.render('board');
},{name:"board.chat"});
//On before actions
var OnBeforeActions = {
    loginRequired: function(){
      if(!Meteor.userId()) {
        this.render('main');
      }else{
        this.next();
      }
    },
    mobileOrDesktop: function(){
      if(findBootstrapEnvironment() != 'xs'){
        this.render('chat',{to:'chat'});
      }else{
        this.render('chat');
      }
      this.next();
    }
};
Router.onBeforeAction(OnBeforeActions.mobileOrDesktop, {
    only: ['board','board.chat']
});
Router.onBeforeAction(OnBeforeActions.loginRequired, {
    only: ['board','board.chat']
});
Router.onBeforeAction('loading');
//Bootstrap state helper
function findBootstrapEnvironment() {
    var envs = ["xs", "sm", "md", "lg"],    
        doc = window.document,
        temp = doc.createElement("div");
    doc.body.appendChild(temp);
    for (var i = envs.length - 1; i >= 0; i--) {
        var env = envs[i];
        temp.className = "hidden-" + env;
        if (temp.offsetParent === null) {
            doc.body.removeChild(temp);
            return env;
        }
    }
    return "";
}

这是我的布局,其中收益率为:

<template name="layout">
    <!--Desktop-->
    <div class="hidden-xs full-height">
        {{> navbar}}
        {{> notifications}}
        {{> yield}}
    </div>
    <!--Mobile-->
    <div class="hidden-sm hidden-md hidden-lg">
        {{> notifications}}
        {{> yield}}
    </div>
</template>
<template name="loading">
Loading...
</template>

这是包含其他产量的文件:

<template name="board">
    <!--Desktop-->
    <div class="container hidden-xs full-height">
        <div class="row" style="height:90%;">
            <!--Projects-->
            <div class="col-sm-4 full-height">
                {{> projects}}
            </div>
            <!--Chat-->
            <div class="col-sm-8 full-height">
                {{> yield "chat"}}
            </div>
        </div>
        <div class="row" style="position:absolute;bottom:0px;left:20px;">
            {{> footer}}
        </div>
    </div>
    <!--Mobile-->
    <div class="hidden-sm hidden-md hidden-lg full-width">
        <!--Projects-->
        {{> projects}}
    </div>
</template>

感谢!!!

1 个答案:

答案 0 :(得分:0)

所以这就是问题,经过一堆摆弄,什么不是,我意识到有两个产量(虽然一个是隐藏的)不受支持。愚蠢的错误!确保你只有一个屈服部分!!