Meteor Html页面出现在单个窗口中

时间:2015-10-27 07:20:26

标签: meteor iron-router

我正在尝试使用铁路由器在点击事件上路由html页面。但是当我运行应用程序时,所有页面都出现在主页面本身,而点击事件并不会路由所需的页面。 JS代码如下

    Template.Login.events({
    'submit form': function(){
    event.preventDefault();
    var username = $('[name=userId]').val();
    var password = $('[name=password]').val();
    if(username == '' && password ==''){
        alert("Please fill all fields...!!!!!!");
    }
    else if( username =='deal' && password ==''){
        alert("You are logged in as a Deal manager");
        Meteor.Router.to("/dashboard");

    }
    else if( username =='practice' && password ==''){
        alert("You are logged in as a Practice manager");
        Meteor.Router.to("/pracDashboard");
    }
    }  
    });

如上所述,登录页面的条件为' deal'或者练习'路由到不同的页面。当我将dashboard.html放在文件夹中时,登录和仪表板页面都出现在同一个窗口中。

1 个答案:

答案 0 :(得分:0)

为了显示页面,我们应该以模板形式转换html页面。让我们说login.html如下

<html>
    <title>Sample title</title>
    <body>Sample Text</body>
</html>

对于meteor,html页面应该是这样的

<template name="login">
     Sample Text
</template>

然后,为了显示登录页面,我们需要像这样实现Route

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

因此,首先设置路由器然后在提交重定向期间的事件中。

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

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

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

Template.login.events({
    'submit form': function(){
        event.preventDefault();
        var username = $('[name=userId]').val();
        var password = $('[name=password]').val();
        if(username == '' && password =='') {
            alert("Please fill all fields...!!!!!!");
        } else if( username =='deal' && password =='') {
            alert("You are logged in as a Deal manager");
            Router.go("/dashboard");
        } else if( username =='practice' && password ==''){
            alert("You are logged in as a Practice manager");
            Router.go("/pracDashboard");
        }
    }  
});