How do I create multi-page applications with Meteor?

前端 未结 5 2041
醉话见心
醉话见心 2021-01-29 21:23

I am new to Javascript and just started fiddling around with Meteor out of curiosity. What really surprises me, is that it seems that all HTML content gets combined into a singl

5条回答
  •  -上瘾入骨i
    2021-01-29 22:07

    As far as I am aware, there is currently no out of the box way to do this.

    What I suggest to do, is to use Backbone.js smart package. Backbone.js comes with the push-state Router, and if the user's browser doesn't support that it will fallback to hash urls.

    In your meteor app directory type this meteor add backbone.

    Then somewhere in your client-side code create a Backbone.js Router like so:

    var Router = Backbone.Router.extend({
      routes: {
        "":                 "main", //this will be http://your_domain/
        "help":             "help"  // http://your_domain/help
      },
    
      main: function() {
        // Your homepage code
        // for example: Session.set('currentPage', 'homePage');
      },
    
      help: function() {
        // Help page
      }
    });
    var app = new Router;
    Meteor.startup(function () {
      Backbone.history.start({pushState: true});
    });
    

    Then somewhere in your Handlebars template, you can create a helper that will render a page based on the value set in Session's "currentPage".

    You can find more information about backbone.js router here: http://backbonejs.org/#Router

    Also relevant information on how to create a Handlebars helper method in Metoer here: http://docs.meteor.com/#templates

    Hope this helps.

提交回复
热议问题