iron router: prevent template rerender?

1,117 views
Skip to first unread message

Davide Dal Colle

unread,
Oct 24, 2013, 6:07:10 AM10/24/13
to meteo...@googlegroups.com
I'd like to use routes to register application states, but the page itself doesn't need to swap templates. 
The routing should register the URL change and just apply effects on html elements, such opening windows or displaying lists of items.

Is this behavior possible with iron router?

Thank you.

Patrick Scott

unread,
Oct 24, 2013, 11:04:11 AM10/24/13
to meteo...@googlegroups.com
Haven't tried it, but according to the documentation it looks like you should be able to provide an action function:

Router.map(function () {
  this.route('postShow', {
    path: '/posts/:_id',

    action: function () {
      // this => instance of RouteController
      // access to:
      //  this.params
      //  this.wait
      //  this.render
      //  this.stop
      //  this.redirect
    }
  });
});

Davide Dal Colle

unread,
Oct 25, 2013, 5:31:46 AM10/25/13
to meteo...@googlegroups.com
The problem with custom action is that, if the user enter the site in that route, no template is specified. But I shall check the documentation better about this

Tom Coleman

unread,
Oct 25, 2013, 9:31:43 PM10/25/13
to meteo...@googlegroups.com
Hi David,

Yes, so for this reason you should make sure you use the same templates and data on all of your related routes.

You can call `this.render()` or just use a hook to ensure they are always rendered.

What Iron Router aims to do is avoid unnecessary re-renders in such situations -- the idea isn't to keep vestiges of old routes around when users browse around -- as you said that doesn't work if they happen to hit refresh.

When the UI branch of Meteor lands we may not even need to do that any more (more investigation is still required).

Cheers,
Tom

--
You received this message because you are subscribed to the Google Groups "meteor-talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to meteor-talk...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Tom Coleman
Development Lead
http://percolatestudio.com
@tmeasday

Kris Haamer

unread,
Nov 8, 2013, 2:19:24 PM11/8/13
to meteo...@googlegroups.com
Hey David, did you manage to get this to work? What i'm trying to do is set globe variables (the site language) based on the route but at least 
with the meteor i18n this is not working.

Chris Mather

unread,
Nov 15, 2013, 10:01:43 AM11/15/13
to meteo...@googlegroups.com
To clarify how the Router deals with rendering (currently): It will only render the template if it's not already rendered into the given yield region. 

For example:
this.render('myTemplate');
this.render('myTemplate');

This will only render myTemplate once, into the main yield region {{yield}}.

So if you register a global before hook that renders the one template you want for all routes, you can override the action function of each individual route to do what you want. 

For example:

```
Router.before(function () {
  this.render('someGlobalTemplate'); // or just use a Router option
});

Router.map(function () {
  this.route('something', {
    path: '/with/:dynamic/:segment',
    action: function () {
      Session.set('dynamic', this.params.dynamic);
      Session.set('segment', this.params.segment);
    }
  });
});
```
Reply all
Reply to author
Forward
0 new messages