Matthew
Matthew

Reputation: 137

Meteor JS Router.go redirect to the same page

I have a problem, in my meteor app when I'm on a page say "test/two", I have a button called "All", now when I click this button I want my meteor app to reload whole "test/two" page with initial data from server (there are some filters and things you can change on "test/two").

The problem is that whether I use anchor or click event to redirect with Router.go meteor recognizes that I'm already on this page and does nothing.

Can I force meteor app to reload from the server the same page that I'm already on?

Upvotes: 1

Views: 932

Answers (2)

FullStack
FullStack

Reputation: 6020

Iron:Router is not necessary if you just want to reload the entire page, you can use pure JavaScript:

document.location.reload(true);

Upvotes: 0

delvedor
delvedor

Reputation: 52

It's not easy as seems.
The problem is that if you do a full refresh of the page, you will get the page with the initial data, but you will lose the session.
Example:
.js

if (Meteor.isClient) {
    Session.setDefault('something', "other");
    console.log(Session.get('something'));
    Template.reload.events({
        'click #reload': function() {
            document.location.reload(true);
        },
        'click #change': function() {
            Session.set('something', 'else');
            console.log(Session.get('something'));
        }
    });
}

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

.html

<head>
    <title>Reload</title>
</head>
<body>
    <h1>Reload test!</h1>
</body>

<template name="layout">
    {{> yield}}
</template>

<template name="reload">
    <button id ="change" type="button">Change Session</button>
    <br/><br/>
    <input type="text">
    <input type="checkbox">
    <input type="checkbox" checked>
    <button id="reload" type="button">Reload</button>
</template>

I made some experiments with iron:router but I did not get any results.
A brute force idea can be save in a object the initial data, and if the user presses the "All" button you will restore the original data with a listener.

In addition I've found this, How do I reload the current iron:router route?, take a look, maybe it's useful.

Upvotes: 0

Related Questions