Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Template didn't rerender when 2 routes render the same template #72

Open
ArthurGerbelot opened this issue Jun 1, 2016 · 5 comments
Open

Comments

@ArthurGerbelot
Copy link

I have 2 route / and /sell linked to the same Template, but when I switch from one to the other, the template isn't reloaded (so ReactiveVar aren't updated).

This is my router:

FlowRouter.route('/', {
  name: "dashboard",
  action() {
    console.log('go to buy');
    BlazeLayout.render("layout", {nav: "publicNav", main: "dashboard"});
  }
});
FlowRouter.route('/sell', {
  name: "dashboard-sell",
  action() {
    console.log('go to sell');
    BlazeLayout.render("layout", {nav: "publicNav", main: "dashboard"});
  }
});

And the basic template onCreated function:

Template.dashboard.onCreated(function () {
  console.log('Route name: ', FlowRouter.current().route.name)
})

So whem I call / and I try to switch multiple times, I got:

go to buy
Route name:  dashboard
go to sell
go to buy
go to sell

And When I start with /sell (hard refresh) I got:

go to sell
Route name:  dashboard-sell
go to buy
go to sell

How can I avoid that ? Or at least bind a function on this update event ?

@ArthurGerbelot ArthurGerbelot changed the title Template didn't rerender when 2 urls display it Template didn't rerender when 2 routes render the same template Jun 1, 2016
@HyperNexus
Copy link

This issue is a duplicate of #65.

Would be great to see this resolved. :)

@svda
Copy link

svda commented Sep 19, 2016

+1

@thoragio
Copy link

thoragio commented Oct 24, 2016

+1

For those who want a hack to work around this issue, I added this IIFE to the onCreated method for the affected template:

(function reloadItOnce() {
    if (window.localStorage) {
      if (!localStorage.getItem('firstLoad')) {
        localStorage.firstLoad = true;
        window.location.reload();
      } else {
        localStorage.removeItem('firstLoad');
      }
    }
  }());

This worked for me since I am not using ReactiveVar/ReactiveDict.

@ArthurGerbelot
Copy link
Author

Another way to do it, use the FlowRouter.watchPathChange() function:

Template.testPage.onCreated(function() {
  Tracker.autorun(function() {
    FlowRouter.watchPathChange();
    /* .. some update here .. */
  });
})

@leedongwei
Copy link

leedongwei commented Nov 19, 2016

This is what I did to get around the issue. I reset BlazeLayout with a global trigger that fires for every route and clean out the DOM. Put this on top of your routes.js file.

function resetBlazeLayout() {
  BlazeLayout.reset();
}

FlowRouter.triggers.enter([resetBlazeLayout]);
  • I can't find the documentation for BlazeLayout.reset() so it is unlikely to be part of the supported API for BlazeLayout. I'm using v2.3.0.
  • You'll need to hunt down bits like onhover-tooltips that are inserted by your UI framework. Not the prettiest solution, but everything about routing is in the same file, which is nice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants