【问题标题】:Meteor.JS when Page navigation on Button Click ,Page loads for a second and again previous page appearsMeteor.JS 当页面导航按钮单击时,页面加载一秒钟并再次出现上一页
【发布时间】:2015-01-11 17:37:13
【问题描述】:

LoginRegister.html 的代码
1.首页
2.所有模板工作正常。我认为html文件没有问题
3.问题出在router.js文件中

         <!--Home Template !-->
         <template name="home">
         {{> login}}
         </template>

         <!--Layout Template !-->
         <template name="layout"> 
             <header>
               {{> topheader }}
             </header>
             {{> yield}}  
         </template>

         <!--TopHeader Template !-->
         <template name="topheader">  
                <h1>Welcome</h1>        
         </template>

         <!--Login Template !-->
         <template name="login">  
           <form class="form-horizontal">
               <button type="submit" class="btn btn-default signin" id="signInBtn ">Sign in</button>         
               <button type="submit" class="btn btn-default signup" id="signUpBtn ">Sign Up</button>        
          </form>
         </template>

         <!--SignUP Template !-->
         <template name="signup">   
                <h1>SIGNUP <small>Page</small></h1>     
         </template>


Router.js 这可以正常工作,当单击 SignUp 按钮时,它会闪烁 sigup 模板,但会再次使用登录页面重新加载主页模板
Router.configure({ layoutTemplate: 'layout'
}); Router.map(function() { this.route('home',{path: '/'}); this.route('signup',{path: '/signup'}); })


loginRegister.js 包含两个按钮单击事件的 Java 脚本文件

          if (Meteor.isClient) {     
           Template.login.events({
                'click .signin': function(evt,tmpl){

                        alert("Sign in button is clicked");
                       console.log("Registration Form submitted.");

                 },
                 'click .signup':function(evt,tmpl)
                 {
                    Router.go('signup', {name: '/signup'});

                 }
           });   
       }

请帮助我被卡住了,我是 Meteor 的新手,所以无法弄清楚,搜索没有产生好的结果

【问题讨论】:

  • Router.go('/signup')

标签: meteor meteor-accounts


【解决方案1】:

您需要阻止您的按钮提交,因此请在您的注册事件处理程序代码中尝试这样的操作:

'click .signup':function(evt,tmpl)
{
  evt.preventDefault(); // add this to prevent the button from submitting
  Router.go('signup', {name: '/signup'});
}

【讨论】:

  • 太棒了!请接受我的回答好吗?谢谢。
猜你喜欢
  • 2019-02-19
  • 2021-08-19
  • 1970-01-01
  • 2014-04-29
  • 1970-01-01
  • 2019-02-17
  • 2013-05-15
  • 2019-03-31
  • 1970-01-01
相关资源
最近更新 更多