1

I'm new to meteor and iron router. Iron router example are not up to date and not working on github. I just want to make a simple route. Here is my /client/index.html

 <html>
  <head>
    <title></title>
  </head>
  <body>

    {{> template1OrTemplate2 depending on url}}
  </body>
</html>


<template name="template1">
  one
</template>

<template name="template2">
  two
</template>

my /lib/router.js:

Router.route('/templateOne', function () {
  // renderMyTemplate1 please
});

Router.route('/templateTwo', function () {
  // renderMyTemplate2 please
});

How is it possible something that easy is so hard to find?

BoumTAC
  • 3,531
  • 6
  • 32
  • 44

2 Answers2

1

Actually iron:router is well documented, and this is as trivial as you would expect.

<head>
  <title></title>
</head>
<body>
  {{> yield}}
</body>


<template name="template1">
  one
</template>

<template name="template2">
  two
</template>



Router.route('/templateOne', function () {
  this.render('template1')
});

Router.route('/templateTwo', function () {
  this.render('template2')
});

However I agree with Keith's comments re flow-router. If you are just starting you probably want to use that instead.

JeremyK
  • 3,240
  • 1
  • 11
  • 24
  • thanks it work but still got an error in the console: Uncaught Error: No Iron.Layout found so you can't use yield!. Can you show me the same example with flowrouter too? or a link to the doc? – BoumTAC Oct 22 '15 at 22:25
  • when you add iron:router to a new project, iron:layout is included. But you can add it individually, `meteor add iron:layout` – JeremyK Oct 22 '15 at 22:29
  • Here is a [meteorpad example](http://meteorpad.com/pad/YH9XPGh9KSKecbdZh/iron:router) – JeremyK Oct 22 '15 at 22:30
1

For Flow Router :-

ensure you have done...

meteor add kadira:flow-router kadira:blaze-layout

then

FlowRouter.route('/templateOne', {
    action() {
        BlazeLayout.render("template1");
    }
}) 

FlowRouter.route('/templateTwo', {
    action() {
        BlazeLayout.render("template2");
    }
}) 

With a layout you'd do something like

<template name="layout">
  <div>My App</div>
   {{>Template.dynamic template=content}}
  </template>

then

FlowRouter.route('/templateOne', {
    action() {
        BlazeLayout.render("layout", {content:"template1"});
    }
}) 
Keith Nicholas
  • 43,549
  • 15
  • 93
  • 156
  • with your example, template are display but I still got error: Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/two." . And I dont understand your last example. Your are rendering the template layout on the url templateOne with the cotnent of template1 and it still working with template2. – BoumTAC Oct 23 '15 at 05:57
  • not sure about your error, the second example is where you use a layout.... you can render different templates into that layout.... so if you have a menu, depending on what you click on in the menu, you will redner different templates perhaps – Keith Nicholas Oct 23 '15 at 07:27
  • You helped me a lot with flow router, I thought I understand well but I still got problem with layout. Could you check it out? http://stackoverflow.com/questions/33356401/meteor-with-flow-router-layout-is-rendered-twice – BoumTAC Oct 26 '15 at 22:10