使用铁路由器路由

安装铁路由器

从终端:

meteor add iron:router

基本配置

Router.configure({
    //Any template in your routes will render to the {{> yield}} you put inside your layout template 
    layoutTemplate: 'layout',
    loadingTemplate: 'loading'
});

无数据渲染

//this is equal to home page
Router.route('/', function (){
    this.render('home')
});

Router.route('/some-route', function () {
    this.render('template-name');
});

使用数据和参数进行渲染

Router.route('/items/:_id', function () {
    this.render('itemPage', {
        data: function() {
            return Items.findOne({_id: this.params._id})
        }
    });
});

渲染到次要输出

Router.route('/one-route/route', function() {
    //template 'oneTemplate' has {{> yield 'secondary'}} in HTML
    this.render('oneTemplate');
    
    //this yields to the secondary place
    this.render('anotherTemplate', {
        to: 'secondary'
    });

    //note that you can write a route  for '/one-route' 
    //then another for '/one-route/route' which will function exactly like above.
});

在渲染模板之前订阅并等待数据

Router.route('/waiting-first', {
    waitOn: function() {
        //subscribes to a publication 
        //shows loading template until subscription is ready
        return Meteor.subscribe('somePublication')
    },

    action: function() {
        //render like above examples
    }
});

订阅多个出版物并在呈现模板之前等待数据

Router.route('/waiting-first', {
    waitOn: function() {
        //subscribes to a publication 
        //shows loading template until subscription is ready
        return [Meteor.subscribe('somePublication1'),Meteor.subscribe('somePublication2')];
    },

    action: function() {
        //render like above examples
    }
});

铁路由器指南: http//iron-meteor.github.io/iron-router/