【问题标题】:Iron router error in meteor 1.0 in production mode生产模式下流星 1.0 中的 Iron Router 错误
【发布时间】:2014-12-08 18:30:05
【问题描述】:

我已将我的流星应用程序从 0.8 升级到 1.0。在生产模式下将其升级到 1.0 之前它工作正常。升级后我面临生产模式的错误。 正如我在 home.js 中定义的那样

Router.map(function() {
  this.route('home', {
    path: '/', 
    controller: 'Controller1'
  });
});

Controller1 = RouteController.extend({  
  layoutTemplate: 'Layout1',      
  onAfterAction: function() {
     setTimeout(function(){  $('#l').focus(); }, 600);
     this.next;
  }  
});

在开发模式下它工作正常,但是当我在生产模式下运行应用程序时,它给了我找不到错误路径。

请帮助我摆脱困境。提前致谢。

【问题讨论】:

  • 开发模式和生产模式到底是什么意思?在这些模式之间切换需要哪些步骤?
  • 在开发模式下意味着我运行meteor -p 3000,在生产模式下意味着我运行meteor -p 3000 --production

标签: meteor iron-router


【解决方案1】:

我和@Moshikaro 有同样的问题:)

看看我正在使用的 Meteorpad。

http://meteorpad.com/pad/fRzpHPYMwRGPirWAD/Routing

[编辑]

您的home.js 应该是这样的

Controller1 = RouteController.extend({
  layoutTemplate: 'Layout1',
  name: 'home',
  onAfterAction: function() {
    Meteor.setTimeout(function() {
      $('#l').focus();
    }, 600);
  }
});

Router.map(function() {
  this.route('home', {
    path: '/',
    controller: 'Controller1'
  });
});

【讨论】:

  • 在开发模式下意味着我运行meteor -p 3000,在生产模式下意味着我运行meteor -p 3000 --production
  • --production模拟生产模式。缩小和捆绑 CSS 和 JS 文件。所以我认为你的javascript在那之后不能正常工作。你能发布你的确切错误日志吗?你试过我的 Meteorpad 解决方案了吗? :)
  • 是的,它没有在控制台中显示任何错误,但在浏览器中它给出了类似这样 Router.route('/', function () { this.render('Home ', { data: function () { return Items.findOne({_id: this.params._id}) } }); });是的,我已经检查了您的解决方案,但没有找到任何答案。谢谢
  • 在我的回答中查看我的编辑部分。将代码粘贴到您当前的 home.js 中,它应该可以工作。如果没有,请将您的完全错误代码粘贴到code 格式化块中的新答案中。谢谢! :)
【解决方案2】:

在迁移到流星 1.0 和 Iron:router 1.0 之后,我不得不修改我的 router.js 文件。首先,我只在 onRun() 和 onBeforeAction() 钩子中包含了 this.next(),你不需要把它放在 onAfterAction AFAIK 中。

此外,我不再使用 Router.map() 并根据文档定义所有路由:https://github.com/EventedMind/iron-router

所以试着像这样修改你的代码:

Router.route('home', function () {
  this.render('home');
}, {
  layoutTemplate: 'Layout1',
  path: '/',
  onAfterAction: function(){
    setTimeout(function(){  $('#l').focus(); }, 600);
  }
});

干杯,

【讨论】:

    猜你喜欢
    • 2015-01-25
    • 2017-07-15
    • 1970-01-01
    • 2015-09-21
    • 1970-01-01
    • 2016-06-30
    • 2014-12-29
    • 2015-01-23
    • 2018-09-06
    相关资源
    最近更新 更多