流星;如何使这项工作,铁路线+模板问题

时间:2016-07-18 03:45:41

标签: javascript meteor

基本上我有一个带有使用steam API的登录按钮的bootstrap导航栏。我带着

返回
C:\Users\Farhan\AppData\Local\.meteor\packages\meteor-tool\1.3.4_4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\fibers\future.js:280
                        throw(ex);
                              ^ ReferenceError: Template is not defined
    at meteorInstall.lib.main.js (lib/main.js:1:1)
    at fileEvaluate (packages/modules-runtime/.npm/package/node_modules/install/install.js:153:1)
    at require (packages/modules-runtime/.npm/package/node_modules/install/install.js:82:1)
    at C:\Users\Farhan\csgofiyav1\.meteor\local\build\programs\server\app\app.js:68:1
    at C:\Users\Farhan\csgofiyav1\.meteor\local\build\programs\server\boot.js:297:10
    at Array.forEach (native)
    at Function._.each._.forEach (C:\Users\Farhan\AppData\Local\.meteor\packages\meteor-tool\1.3.4_4\mt-os.windows.x86_32\dev_bundle\server-lib\node_modules\underscore\underscore.js:79:11)
    at C:\Users\Farhan\csgofiyav1\.meteor\local\build\programs\server\boot.js:133:5 Exited with code: 8 Your application is crashing. Waiting for file change.

作为我的错误。我的代码是:

在layoutDefault.html

<template name="layoutDefault">
    ..
                        <a class="steamLogin" href="#">Login With Steam</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>
    {{> yield}}
    </template>  

并在main.js

Template.layoutDefault.events({
    'click .steamLogin': function(event){
        Meteor.loginWithSteam();
    }
});

routes.js

Router.configure({
    layoutTemplate: 'layoutDefault'
});

Router.route('/', {
    template: 'main'
});

Router.route('/contact', {
    template: 'contact'
});

任何帮助表示赞赏!

2 个答案:

答案 0 :(得分:0)

错误不再存在,但现在说

Unable to resolve some modules:

  "./layoutDefault.html" in /C/Users/Farhan/csgofiyav1/client/main.js
(web.browser)

将main.js发送到客户端文件夹

的客户机/ main.js

import { Template } from 'meteor/templating';

import './templates/layout/layoutDefault.html';

Template.layoutDefault.events({
    'click .steamLogin': function(event){
        Meteor.loginWithSteam();
    }
});

的客户机/模板/布局/ layoutDefault.html

<template name="layoutDefault">
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        .....
                    <li>
                        <a class="steamLogin" href="#">Login With Steam</a>
                    </li>
                </ul>
            </div>
            <!-- /.navbar-collapse -->
        </div>
        <!-- /.container -->
    </nav>

    {{> yield}}
    </template>  

答案 1 :(得分:0)

好的,现在正在工作。我不得不更新服务器端main.js

添加了这个

    if(Meteor.isServer) {
  Meteor.startup(function () {
    ServiceConfiguration.configurations.upsert(
      { service: 'steam' },
      {
        $set: {
          loginStyle: 'redirect',
          timeout: 10000 // 10 seconds
        }
      }
    );
  });
}

然后我没有为模板创建事件,而是将链接路由到login.html,在客户端js中,一旦呈现该模板,我将运行Meteor.loginWithSteam();

Template.login.rendered = function() {
    if(!this._rendered) {
      this._rendered = true;
      Meteor.loginWithSteam();
    }
}