流星应用中的铁路由器问题

Iron router issue in meteor application

我正在做我的第一个 Meteor 应用程序,在使用 iron router 进行导航时遇到了一些问题。每次,我单击签名模板中的登录按钮,它都不会将我重定向到主页模板。单击签名按钮 (http://localhost:3000/?) 后,浏览器会显示一个带有问号的 url。奇怪的是,在我单击浏览器中的后退按钮后,它会将我带到 URL 主页:http://localhost:3000/home。我不明白为什么会这样。请帮我找出我做错了什么。

在router.js文件中,我写了:

Router.configure({

  layoutTemplate: 'layout',


});



Router.map(function() {


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

});

布局文件如下所示:

<template name="layout">

    <div>
        {{>header}}
    </div>


    <div>
        {{>yield}}
    </div>

    <div>
        {{>footer}}
    </div>

</template>

登录模板文件如下所示:

<template name="signin">

  <div class="container">

    <div class="row">
        <div class="col-sm-6 col-md-4 col-md-offset-4">

            <div class="account-wall">
                <h1 class="text-center login-title">Sign in to continue</h1>
                <form class="form-signin">
                <input type="text" class="form-control" placeholder="Email" required autofocus>
                <input type="password" class="form-control" placeholder="Password" required>
                <button class="btn btn-lg btn-primary btn-block" type="submit">
                    Sign in</button>
                <label class="checkbox pull-left">
                    <input type="checkbox" value="remember-me">
                    Remember me
                </label>
                <a href="#" class="pull-right need-help">Need help? </a><span class="clearfix"></span>
                </form>
            </div>
            <a href="#" class="text-center new-account">Create an account </a>
        </div>
    </div>
</div>


</template>

首页模板如下:

<template name="home">    
        <div class="row">
            <div class="col-sm-4">
                <h3>Column 1</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
                <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
            </div>
            <div class="col-sm-4">
                <h3>Column 2</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
                <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
            </div>
            <div class="col-sm-4">
                <h3>Column 3</h3>
                <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit...</p>
                <p>Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris...</p>
            </div>
        </div>
</template>

Signin.js文件的代码如下:

if (Meteor.isClient) 
{


    console.log("Sign In JS");

    Template.signin.helpers({

    });

    Template.signin.events({

        'submit': function(event, template) {
           // alert("My button was clicked!");
            Router.go('home');
        }
    });
}

根据你的情况,你必须使用 path Router.go("/home")