简体   繁体   English

流星铁路由器强制页面刷新

[英]Meteor Iron-Router force page refresh

I just recently started working with Meteor and Iron Router , so I'm having some issues. 我刚刚开始使用MeteorIron Router ,所以遇到了一些问题。

I am looking to have a very basic website and am nearly there but when it comes to reusing one of the templates for various directories, the page doesn't refresh which causes it to show the previous page despite the URL showing the correct page. 我正在寻找一个非常基本的网站,并且几乎在那儿,但是在重用各个目录的模板之一时,该页面不会刷新,尽管URL显示正确的页面,但该页面仍显示上一页。

Once I hit refresh on the browser then the page will actually reload with the correct page, but I would rather not have to always refresh the page and would like to simply just have to click on a link and get the correct information . 一旦在浏览器中单击“刷新”,该页面实际上就会重新加载正确的页面,但是我宁愿不必始终刷新页面, 而只需要单击链接并获取正确的信息即可

I have attempted some of the solutions that I have seen pertaining to similar issues, but they all seemed to be a bit more unique than mine. 我尝试了一些与类似问题相关的解决方案,但它们似乎都比我的独特。 I have included my .js file from 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});
        }

    });
}

Your problem is that parseddir is not reactive . 您的问题是parseddir没有反应

A solution is to follow the doc rendering template with data for iron router. 一种解决方案是将文档渲染模板与铁路由器的数据一起使用。 Just give parseddir as data to the profile template when you render it and in your helper use this.parseddir to get the actual data. 只需在呈现profile模板时将parseddir作为数据提供给profile模板,然后在助手中使用this.parseddir即可获取实际数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM