【问题标题】:Meteor Iron-Router force page refreshMeteor Iron-Router 强制页面刷新
【发布时间】:2018-06-19 00:01:56
【问题描述】:

我最近才开始使用 MeteorIron Router,所以我遇到了一些问题。

我希望有一个非常基本的网站,并且快到了,但是在为各种目录重用其中一个模板时,页面不会刷新,这会导致它显示上一页,尽管 URL 显示正确页。

一旦我在浏览器上点击刷新,页面实际上会重新加载正确的页面,但我宁愿不必总是刷新页面,只想简单地点击一个链接并获取正确的信息

我尝试了一些我见过的与类似问题有关的解决方案,但它们似乎都比我的更独特。我已经包含了来自 meteor.js 文件。

Router.route('/', function () {
  this.render('iotprofiler');
});

Router.route('index.html', function () {
  this.render('iotprofiler');
});

Router.route('/device(.*)', function () {
  //document.location.reload(true);
  this.render('profile');

});


if(Meteor.isClient){
    //this code only runs on the client

    var directory = Iron.Location.get().path;
    var start = directory.lastIndexOf("/");
    var stop = directory.search(".html");
    var parseddir = directory.slice(start + 1,stop);
    console.log(parseddir);

    Template.iotprofiler.helpers({
        'device': function(){
            return DeviceList.find();
        }
    });

    Template.profile.helpers({
        'iotdevice': function(){
            return DeviceList.find({model: parseddir});
        }

    });
}

【问题讨论】:

    标签: javascript meteor refresh router iron-router


    【解决方案1】:

    你的问题是parseddir 不是reactive

    解决方案是遵循文档rendering template with data 获取 Iron 路由器。 渲染时只需将parseddir 作为数据提供给profile 模板,并在帮助程序中使用this.parseddir 获取实际数据。

    【讨论】:

      猜你喜欢
      • 2014-07-17
      • 2014-10-23
      • 1970-01-01
      • 2021-10-28
      • 1970-01-01
      • 2014-05-07
      • 2013-11-21
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多