【问题标题】:Routing in MeteorMeteor 中的路由
【发布时间】:2012-11-17 07:18:09
【问题描述】:

在 Meteor 中,我使用 Backbone 为我的应用程序中的不同页面提供路由。我目前有一个个人资料和一个管理页面。当我进入个人资料页面时,它会按原样显示,但是当我进入管理页面时,Meteor 会退回到主页。

作为旁注,如果有人对 Meteor 中的页面有更好的模式或最佳实践,请随时分享,因为这很麻烦。

我使用以下模板来决定要显示的页面:

<template name="root">
    {{> navbar}}
    {{#if pageIs "profile"}}
      {{> profile}}
      {{else}}{{#if pageIs "administration"}}
        {{> administration}}
      {{else}}
        {{> main_page}}
      {{/if}}
    {{/if}}
</template>

pageIs方法如下:

Template.root.pageIs = function(page){
    console.log(Session.get('page'));
    return page === Session.get('page');
}

我的 Backbone 路由器中的以下代码:

var ProtonRouter = Backbone.Router.extend({
    routes: {
        "profile": "profile",
        "admin": "administration",
        "administration":"administration"
    },
    profile: function () {
        Session.set('page','profile');
    },
    administration: function (){
        Session.set('page', 'administraion');
    },
    mainPage: function(){
        Session.set('page',null);
    }
});

pageIs 方法中的 log 语句将记录 undefined 几次,然后记录正确的页面,即使在管理时也是如此,但是 Meteor 似乎无论如何都不会重新加载选定的页面,模板仍然会命中最后一个 else 语句.

【问题讨论】:

    标签: javascript meteor


    【解决方案1】:

    更新:Iron 路由器已被弃用,取而代之的是 Flow 路由器。以后还有strong indications that Flow Router will be supported as part of core Meteor

    https://github.com/meteorhacks/flow-router

    过时:以前常用的路由器是 Iron Router:

    https://github.com/EventedMind/iron-router

    在发布时,Iron Router 结合了两个最广泛使用的流星路由器(meteor-routermini-pages)的作者的努力,并且是流路由器之前的流星事实上的官方路由器。

    【讨论】:

      【解决方案2】:

      很多人使用这个路线系统:

      https://github.com/tmeasday/meteor-router

      它非常易于使用,并且专为 Meteor 制作。

      【讨论】:

      • 谢谢!会试试看的。
      • 现在已经过时了,开发也停止了。请参阅已接受的继任者帖子。
      【解决方案3】:

      在 Meteor 的早期,建议使用 Backbone 进行路由。

      安德鲁在他的帖子中指出的路由器,已成为最受欢迎的选择:https://github.com/iron-meteor/iron-router

      更简约的解决方案是流路由器:https://github.com/meteorhacks/flow-router

      要做出明智的决定,请使用两个路由器的read about the differences

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-07-10
        • 1970-01-01
        • 2016-06-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多