如何在特定页面上启动Meteor应用程序?如果您不对此进行控制,那么当您上次关闭应用时,浏览器会记住您在应用中的位置,并尝试加载该旧位置。哪个好,如果这是你想要的,但如果没有,那你做什么?
在我的应用中使用铁路由器,这曾经起作用:
Meteor.startup(function () {
Router.go('/');
});
现在这会在Router.js中抛出一个错误,抱怨self._location未定义。好像现在对Router.go()的调用发生得太快了。有没有办法知道Router何时准备好进行go()调用?或者在这里引入延迟的方法?
_________________ EDIT _________________
为了解决这个问题,我已将所有内容减少到必需品。这是我的所有代码,共2个文件:
newPL.js:
Router.configure({
layoutTemplate: 'layout'
});
Router.map(function () {
this.route('home', {
path: '/',
});
this.route('main', {
path: '/main',
});
});
if (Meteor.isClient) {
Meteor.startup(function () {
Router.go('home');
});
}
和newPL.html:
<head>
<title>newPL</title>
</head>
<template name='layout'>
<div>
{{> yield}}
</div>
</template>
<template name='home'>
<div>
Welcome to Planet Lingo!
<a href='/main'>GO</a>
</div>
</template>
<template name='main'>
<div>
<h1>Main</h1>
</div>
</template>
答案 0 :(得分:2)
这看起来像铁路由器中的一个错误。 Iron路由器在router.start周围执行Meteor.defer,请参阅:Iron-router source第34行
您可以自己使用Meteor.defer来解决这个问题
Meteor.startup(function () {
Meteor.defer(function () {Router.go('home');});
});
这可以正常工作,因为你的延迟被置于由铁路由器
创建的那个之下