【发布时间】:2014-05-23 22:39:38
【问题描述】:
如何让 Meteor 应用在特定页面上启动?如果您不对此进行控制,则浏览器会记住您上次关闭应用程序时您在应用程序中的位置,并尝试加载该旧位置。这很好,如果这是你想要的,但如果不是,那你怎么办?
在我的应用程序中使用 Iron-router,这曾经可以工作:
Meteor.startup(function () {
Router.go('/');
});
现在这会在 Router.js 中引发错误,抱怨 self._location 未定义。就好像对 Router.go() 的调用现在发生得太快了。有没有办法知道路由器何时准备好进行 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>
【问题讨论】:
标签: meteor iron-router