Meteor;我该如何让它工作,铁路线+模板问题
2016-07-18
115
基本上,我有一个带有登录按钮的 bootstrap 导航栏,它使用 steam API。我返回了
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个回答
错误不再存在,但是,现在显示
Unable to resolve some modules:
"./layoutDefault.html" in /C/Users/Farhan/csgofiyav1/client/main.js
(web.browser)
将 main.js 移至客户端文件夹
client/main.js
import { Template } from 'meteor/templating';
import './templates/layout/layoutDefault.html';
Template.layoutDefault.events({
'click .steamLogin': function(event){
Meteor.loginWithSteam();
}
});
client/templates/layout/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>
Farhan
2016-07-18
好的,现在可以正常工作了。我必须更新服务器端 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();
}
}
Farhan
2016-07-18