2015-05-13 108 views
0

在我的流星项目中,我必须在客户端文件夹内的html页面。一个是home.html,另一个是contact.html。而运行项目浏览器则显示两个页面。 我的第一个问题是如何只运行第一页。 第二在菜单部分,当我点击联系人选项卡时,它应该在联系人页面上呈现。无论如何在流星中加载一页到另一页。如何从一个页面导航到另一个流星页面

+1

分享你到目前为止试图HTML – garima

回答

1

阅读:https://github.com/iron-meteor/iron-router/tree/devel/examples

JS文件:

Router.route('/', function() { 
// render the Home template with a custom data context 
this.render('Home', {data: {title: 'My Title'}}); 
}); 
// when you navigate to "/one" automatically render the template named "One". 
Router.route('/Home'); 
// when you navigate to "/two" automatically render the template named "Two". 
Router.route('/Contact'); 

HTML文件:

<head> 
    <title>basic</title> 
</head> 
<template name="Home"> 
    {{> Nav}} 
    <h1>Home</h1> 
    <p>Data Title: {{title}}</p> 
</template> 
<template name="One"> 
    {{> Nav}} 
    <h1>Page One</h1> 
</template> 
<template name="Two"> 
    {{> Nav}} 
    <h1>Page Two</h1> 
</template> 
<template name="Nav"> 
    <ul> 
     <li> 
      <a href="/">Home</a> 
     </li> 
     <li> 
      <a href="/one">Page One</a> 
     </li> 
     <li> 
      <a href="/two">Page Two</a> 
     </li> 
    </ul> 
</template> 
0

的方法之一是使用如铁路由器包:https://github.com/iron-meteor/iron-router

然后,您就可以设置路线,如: //定义根路径和渲染家庭模板

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

一旦你定义的各种途径(映射到对应的模板),然后你可以这样做:

<nav> 
    <a href="{{ pathFor 'contact' }}">Contact</a> 
</nav> 
相关问题