javascript - Make Iron Router reload page when clicking on the same link - Stack Overflow

I just started playing around with Meteor and Iron Router to create a simple site. There are a few link

I just started playing around with Meteor and Iron Router to create a simple site. There are a few links on the nav bar of the site and one of them is called random. The idea is that when a user clicks it, a random post would display at the page.

Now Iron Router seems to prevent a page from reloading if it's the same link with the current one. That's a great feature except in my case I need it to reload so the user can see a new post.

Here's the relevant code:

Router.route('/random', function() {
    console.log("running this!");
    this.layout('SinglePostLayout', {
        data: function () { return draw(Posts, {}) }
    });
    this.render('post');

The draw function returns a post in the collection. It's fun from perfect but that's not relevant here. I confirmed the code only ran once by using console.log.

Is there a way around this? I want to preserve the no reloading behaviour for all other links except for the random one. I've searched for answers for a while but couldn't find anything.

Thanks!

I just started playing around with Meteor and Iron Router to create a simple site. There are a few links on the nav bar of the site and one of them is called random. The idea is that when a user clicks it, a random post would display at the page.

Now Iron Router seems to prevent a page from reloading if it's the same link with the current one. That's a great feature except in my case I need it to reload so the user can see a new post.

Here's the relevant code:

Router.route('/random', function() {
    console.log("running this!");
    this.layout('SinglePostLayout', {
        data: function () { return draw(Posts, {}) }
    });
    this.render('post');

The draw function returns a post in the collection. It's fun from perfect but that's not relevant here. I confirmed the code only ran once by using console.log.

Is there a way around this? I want to preserve the no reloading behaviour for all other links except for the random one. I've searched for answers for a while but couldn't find anything.

Thanks!

Share Improve this question asked Apr 4, 2015 at 18:00 GnijuohzGnijuohz 3,3646 gold badges34 silver badges48 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 7

Since you are not using dynamic routes to show each post.

You can use the Location.reload() method from the window object, and use pure Javascript.

  if(Meteor.isClient){
    Template.home.events({
        'click #randomHref':function(){
            document.location.reload(true);
            // Router.go('/') don't work.
        }
    })
}

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744735758a4590735.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信