【问题标题】:What changes in the execution of an iron router route when coming in on a deep link?当进入深度链接时,铁路由路由的执行会发生什么变化?
【发布时间】:2014-04-28 13:53:49
【问题描述】:

我有一个小流星应用程序与铁路由器一起使用。这是我的 routes.js,客户端和服务器都可以使用:

Router.configure({
  layoutTemplate: 'defaultLayout',
  loadingTemplate: 'loading'
});

// Map individual routes    
Router.map(function() {
  this.route('comicCreate', {
    path: '/comic/create'
  });

  this.route('comicDetails', {
    onBeforeAction: function () {
      window.scrollTo(0, 0);
    },
    path: '/comic/:_id',
    layoutTemplate: 'youtubeLayout',
    data: function() { return Comics.findOne(this.params._id); }
  });

  this.route('frontPage', {
    path: '/',
    layoutTemplate: 'frontPageLayout'
  });

  this.route('notFound', {
    path: '*',
    where: 'server',
    action: function() {
      this.response.statusCode = 404;
      this.response.end('Not Found!');
    }
  });    
});

我需要将我的漫画收藏文档中的一些字段输入到包装 Youtube 的 IFrame API 的包中,我正在通过渲染函数执行此操作:

Template.comicDetails.rendered = function() {
  var yt = new YTBackground();

  if (this.data)
  {
    yt.startPlayer(document.getElementById('wrap'), {
      videoIds: this.data.youtubeIds,
      muteButtonClass: 'volume-mute',
      volumeDownButtonClass: 'volume-down',
      volumeUpButtonClass: 'volume-up'
    });
  }    
};

当我首先转到 localhost:3000/ 然后单击设置为“{{pathFor 'comicDetails'_id}}”的链接时,这非常有用。但是,如果我直接访问 localhost:3000/comic/somevalidid,则不会,尽管两条路线最终都指向同一个 url。

原因似乎是当我直接进入深层链接时,“this.data”在渲染函数执行期间未定义。模板本身显示得很好(数据正确替换了我模板中的空格键 {{field}} 标记),但是当渲染的回调触发时,“this”上下文中没有任何数据。

我在这里做错了吗?

【问题讨论】:

    标签: meteor iron-router


    【解决方案1】:

    尝试在 Meteor.startup 中声明路由...不确定是否是问题所在,但值得一试

    【讨论】:

      猜你喜欢
      • 2019-03-17
      • 1970-01-01
      • 2016-10-10
      • 1970-01-01
      • 2017-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-01-22
      相关资源
      最近更新 更多