使用 iron:router 在 Meteor 中刷新页面总是清除路由

Refreshing page in Meteor with iron:router always clears route

我有一个使用 iron:router 包开发的 Meteor 应用程序。我知道我的用户会有重新加载页面的倾向,因为每个人都喜欢偶尔这样做。

我的问题是每次重新加载页面时它都会返回到我的 Meteor 应用程序的主页。

有没有办法让应用程序在重新加载页面时保持在原来的路线上?

这是我的路线代码:

Router.configure({
  layoutTemplate: 'layout', // Defines the layout template
  loadingTemplate: 'loading' // Defines the loading template
});

// Add the dataNotFound plugin, which is responsible for
// rendering the dataNotFound template if your RouteController
// data function returns a false value
Router.plugin('dataNotFound', {
  notFoundTemplate: 'dataNotFound'
});

Router.route('/', {
  name: 'home',
  template: 'home'
});

Router.route('/signup');
Router.route('/login');
Router.route('/recoverpassword');
Router.route('/resetpassword');

这是与布局相关的所有内容:

<template name="layout">
  {{> navigation}}
  {{> yield}}
  {{> footer}}
</template>

<head>
  <title>Ecclesia.Life</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
</head>

<body>
  <!-- Dropdown menu script -->
  <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.0/js/bootstrap.min.js"></script>
</body>   

<template name="navigation">
<nav class="navbar navbar-default">
    <div class="container-fluid">
        <div class="navbar-header">
            <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
                <span class="sr-only">Toggle navigation</span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
                <span class="icon-bar"></span>
            </button>
            <a class="navbar-brand" href="{{pathFor route='home'}}">Ecclesia.Life</a>
        </div>

        <div class="navbar-collapse collapse" id="navbar-collapse" aria-expanded="false" style="height: 1px;">
            <ul class="nav navbar-nav">
                <li><a href="{{pathFor route='home'}}"><span class="glyphicon glyphicon-home"></span>&nbsp;&nbsp;&nbsp;&nbsp;Home</a></li>
                <li><a id="qrScanner" href="#" onclick="inDevelopment();"><span class="glyphicon glyphicon-qrcode"></span>&nbsp;&nbsp;&nbsp;&nbsp;QR Scanner</a></li>
                <script>
                    $('#qrScanner').click(function() {
                        alert("Still in in development");
                    });
                </script>
            </ul>
            <ul class="nav navbar-nav navbar-right">
                {{#if currentUser}}
                    {{#if isInRole 'admin'}}
                        <li class="dropdown">
                            <a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false"><span class="glyphicon glyphicon-cog"></span>&nbsp;&nbsp;&nbsp;&nbsp;Maintenance <span class="caret"></span></a>
                            <ul class="dropdown-menu">
                                <li>
                                    <a href="/manageusers"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;&nbsp;&nbsp;Manage Users</a>
                                </li>
                                <li><a href="/addqrpage"><span class="glyphicon glyphicon-plus"></span>&nbsp;&nbsp;&nbsp;&nbsp;Add QR Page</a></li>
                            </ul>
                        </li>
                    {{/if}}
                    <li><a href="/@{{currentUser.username}}"><span class="glyphicon glyphicon-user"></span>&nbsp;&nbsp;&nbsp;&nbsp;{{currentUser.profile.firstName}}&nbsp;{{currentUser.profile.lastName}}</a></li>
                    <li><a id="logout" href="{{pathFor route='login'}}"><span class="glyphicon glyphicon-log-out"></span>&nbsp;&nbsp;&nbsp;&nbsp;Log out</a></li>
                {{else}}
                    <li><a href="{{pathFor route='login'}}"><span class="glyphicon glyphicon-log-in"></span>&nbsp;&nbsp;&nbsp;&nbsp;Log in</a></li>
                    <li><a href="{{pathFor route='signup'}}"><span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;&nbsp;&nbsp;Sign up</a></li>
                {{/if}}
            </ul>
        </div>
    </div>
</nav>

<template name="footer">
    <footer class="footer footer-default">
        <div class="container-fluid">
            <hr />
            <p class="text-muted">Copyright &copy; Ecclesia.Life, 2015.</p>
        </div>
    </footer>
</template>

好的,我进行了小测试 repo,一切正常。尝试一下,也许您会发现代码中的差异。如果它仍然不起作用,post 更多代码(至少模板定义)和你的文件在什么文件夹中。还有你安装了什么包。