iron-meteor / iron-router

A client and server side router designed specifically for Meteor.
MIT License
1.98k stars 413 forks source link

Idea: Make renderRegions method unnecessary #969

Open boustanihani opened 9 years ago

boustanihani commented 9 years ago

I am using iron:router@=1.0.0-rc.1

Regions are missing when using this.render('templatename') inside a route!

For reproduction goto http://missing-regions.meteor.com/ then click Page 2 and notice how the content of Region 1 will disappear.

Repo: https://github.com/boustanihani/missing-regions

<template name="defaultLayout">
  <h3>Default Layout</h3>

  <div style="border:solid;padding:1em">
    <h3>Region 1</h3>
    {{> yield 'region1'}}
  </div>

  <br>
  <div style="border:solid;padding:1em">{{> yield}}</div>
</template>

<template name="putInRegion1">
  <h4>Region 1 Content</h4>
  <h4 style="color:red">Empty when using this.render('templatename')</h4>
</template>

<template name="page1">
  <h4>Page 1</h4>
  Goto: <a href="/page2">Page 2</a>
</template>

<template name="page2">
  <h4>Page 2</h4>
  Goto: <a href="/">Page 1</a>
</template>
Router.configure({
  yieldTemplates: {
    'putInRegion1': {
      to: 'region1'
    }
  },
  layoutTemplate: 'defaultLayout',
});

Router.route('/', {
  template: 'page1'
});

Router.route('/page2', function() {
  this.render('page2');
});
cmather commented 9 years ago

Hey @boustanihani, you need to explicitly say this.renderRegions if you want to render the regions from your options. This happens automatically if you use this.render() // no template name.

boustanihani commented 9 years ago

Don't you think this should also be the default behaviour when passing a template name?

Take the following example from the docs: http://eventedmind.github.io/iron-router/#using-hooks

You would like to render the 'Login' template on specific routes if the user is not logged. Naturally you would also want the whole template with all regions to be rendered:

Router.onBeforeAction(function () {
  // all properties available in the route function
  // are also available here such as this.params

  if (!Meteor.user()) {
    // if the user is not logged in, render the Login template
    this.render('Login');
  } else {
    // otherwise don't hold up the rest of hooks or our route/action function
    from running
    this.next();
  }
});
boustanihani commented 9 years ago

How about adding the option { renderRegions : false } to render() for further needs ?

cmather commented 9 years ago

We could update the API. Going to move this to brainstorming so we can continue discussion there.