Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/364.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 用铁流星做路线_Javascript_Meteor_Iron Router_Router - Fatal编程技术网

Javascript 用铁流星做路线

Javascript 用铁流星做路线,javascript,meteor,iron-router,router,Javascript,Meteor,Iron Router,Router,我是流星和铁路由器的新手。Iron路由器示例不是最新的,也不适用于github。 我只想做一条简单的路线。 这是my/client/index.html <html> <head> <title></title> </head> <body> {{> template1OrTemplate2 depending on url}} </body> </html>

我是流星和铁路由器的新手。Iron路由器示例不是最新的,也不适用于github。 我只想做一条简单的路线。 这是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>
怎么可能有这么容易就这么难找到的东西呢?

事实上,iron:router是,这就像你所期望的一样微不足道

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

{{>产量}
一
二
Router.route('/templateOne',函数(){
this.render('template1')
});
Router.route('/templateTwo',函数(){
this.render('template2')
});
不过,我同意基思的评论。如果您刚刚开始,您可能想改用它。

对于Flow Router:-

确保你已经完成了

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

用一个布局你会做一些

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

Iron Router很好,但是,就Meteor生态系统而言,FlowRouter是前进的方向。这也是flow Router的文档,首先我已经观看了FlowRouter,但它仍然看起来很复杂,只是路由。我没有找到如何使用FlowRouter执行我的示例,但仍然在控制台中出错:未捕获错误:没有熨斗。找到布局,因此无法使用yield!。你能给我看一下同样的flowrouter的例子吗?或者文档的链接?当您将iron:router添加到新项目时,iron:layout将包括在内。但是您可以单独添加它,
meteor add iron:layout
下面是一个示例,显示了模板,但仍然出现错误:哦,看起来客户端或服务器上没有url:“.”的路由。我不明白你最后的例子。您正在使用template1的组件在url templateOne上呈现模板布局,它仍在使用template2。不确定您的错误,第二个示例是您使用布局的地方。。。。您可以将不同的模板呈现到该布局中。。。。因此,如果你有一个菜单,根据你在菜单中点击的内容,你会重新编辑不同的模板。也许你在flow router方面帮了我很多,我想我很理解,但我仍然对布局有问题。你能看看吗?
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"});
    }
})