Meteor中带有铁的刷新页面:路由器始终清除路由

时间:2016-01-27 20:52:00

标签: javascript meteor reload iron-router page-refresh

我有一个我使用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>

1 个答案:

答案 0 :(得分:1)

好的,我把小测试repo放在一起,一切都很完美。尝试一下,也许你会发现你的代码有所不同。如果它仍然不起作用,请发布更多代码(至少是模板定义)以及您拥有文件的文件夹。还有你安装的软件包。