question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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 ?

Issue Analytics

  • State:open
  • Created 7 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
leedongweicommented, 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.
0reactions
ArthurGerbelotcommented, Oct 27, 2016

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

Template.testPage.onCreated(function() {
  Tracker.autorun(function() {
    FlowRouter.watchPathChange();
    /* .. some update here .. */
  });
})
Read more comments on GitHub >

github_iconTop Results From Across the Web

iron:router will not re-render after route change with same ...
It does this by using the same template with different parameters. I can see the url change as I am switching routes, if...
Read more >
Prevent re-rendering of template when transitioning to a route
I have a route and an associated template. The template provides a skeleton div into which I manually render content instead of using...
Read more >
Ultimate React Router v6 Guide
If you want to render two different sections of content that both depend on the URL of the application then you need multiple...
Read more >
How To Navigate Between Views with Vue Router
User interface (UI) frameworks like Vue.js render these pages and compone… ... In this example, if you were to visit a route of ......
Read more >
How React Hooks can replace React Router - LogRocket Blog
Looking for an alternative form of routing in your React projects? ... Some things we didn't have issues with before have started causing ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found