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 don't rerender when id change #65

Open
gsabran opened this issue Feb 24, 2016 · 7 comments
Open

Template don't rerender when id change #65

gsabran opened this issue Feb 24, 2016 · 7 comments

Comments

@gsabran
Copy link

gsabran commented Feb 24, 2016

It seems that template don't re render when the id change. For instance if my route looks like this:

FlowRouter.route('/u/:_id', {
  name: 'userItem',
  action: function() {
    console.log('go to ', FlowRouter.getParam('_id'));
    BlazeLayout.render( 'appBody', { main: 'userItem', options: {_id: FlowRouter.getParam('_id')} } );
  },
});

and I go from /u/id1 to /u/id2, I get a log as excepted, but the template is not re created. Is that by design of BlazeLayout? It would be nice to have an option to recreate the template, especially when doing template level subscriptions that should be closed when the id change.

@arunoda
Copy link
Contributor

arunoda commented Feb 28, 2016

It's weird. Try to get the params and queryParams from the action.
See:

FlowRouter.route('/blog/:postId', {
    // do some action for this route
    action: function(params, queryParams) {
        console.log("Params:", params);
        console.log("Query Params:", queryParams);
    },

    name: "<name for the route>" // optional
});

@gsabran
Copy link
Author

gsabran commented Feb 29, 2016

That part works fine, and the logs log different query params as excepted; but this doesn't trigger a template rerender.
Isn't it because here the options are only looked as a key, and the values, which is the part that differ, are not compared? So what ever the value of options is, it's not looked at?
Maybe it would make more sense to have a signature like
BlazeLayout.render = function render(layout, regions={}, options={}) instead of function render(layout, regions={})

@ArthurGerbelot
Copy link

ArthurGerbelot commented Oct 31, 2016

@gsabran did you try this FlowRouter.watchPathChange() :

Template.appBody.onCreated(function() {
  console.log("Init : ", FlowRouter.getParam('_id'))

  this.autorun(function() {
    FlowRouter.watchPathChange();
    /* .. some update here .. */
    console.log("Updated : ", FlowRouter.getParam('_id'))
  });
})

@joshuadavidson
Copy link

@arunoda I have a similar issue. My templates are not firing onCreated when navigating between routes with different parameters. None of the 'fixes' from this thread, #21, or #72 work. Only thing that I have got to work is calling BlazeLayout.reset() on each route change which is terrible. Any help would be appreciated.

@MichaelJCole
Copy link

Hmmm... BlazeLayout.reset(); worked for me. Rerendering once per route change seems like a small matter.

@mklueh
Copy link

mklueh commented Nov 11, 2017

@MichaelJCole in my case it reloads the complete site which is really ugly.

Is there still no solution to force a route change on the same layout after over two years?

@afriC84
Copy link

afriC84 commented Jan 24, 2018

Also ran into that problem. Same route, different params, no reaction.
Calling BlazeLayout.reset() before FlowRouter.go() forces the re-render successfully, but I agree: that feels ugly.

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

7 participants