用铁路由器流星制作路线

时间:2015-10-22 22:10:19

标签: javascript meteor iron-router router

我是流星和铁路由器的新手。 Iron路由器示例不是最新的,不能在github上运行。 我只是想做一个简单的路线。 这是我的/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>

我的/lib/router.js:

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

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

如何才能找到容易找到的东西?

2 个答案:

答案 0 :(得分:1)

实际上是铁:路由器是well documented,这和你想象的一样微不足道。

<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')
});

但是我同意Keith的评论re flow-router。如果你刚刚开始,你可能想要使用它。

答案 1 :(得分:1)

对于Flow Router: -

确保你已经完成......

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

然后

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

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

使用布局,您可以执行类似

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

然后

FlowRouter.route('/templateOne', {
    action() {
        BlazeLayout.render("layout", {content:"template1"});
    }
}) 
相关问题