Meteor: iron route's url参数问题

Meteor: issue with iron route's url parameters

本文关键字:url 参数 问题 iron route Meteor      更新时间:2023-09-26

我正在尝试设置如下路由

Router.configure({
    layout: 'layout',
    loadingTemplate: 'loading',
    notFoundTemplate: 'notFound'
});
Router.map(function () {
    /*
    this.route('/', {
        controller: 'MyController',
        action: 'start'
    });
    */
    this.route('/:a/:b', {
        controller: 'MyController',
        action: 'start'
    });
});

控制器看起来像这样

MyController = RouteController.extend({
    template: 'barfoo',
    before: function () {
        var a = this.params.a,
            b = this.params.b;
        ...
    },
    waitOn: function () { ... },
    data: {  ... },
    start: function () {
});

问题是before函数永远不会被调用。如果我输入

...
this.route('/', {
    controller: 'MyController',
    action: 'start'
});

调用before函数。我在控制台上没有看到任何错误。我一定是漏掉了什么,有什么建议吗?

在我看来,这条路由实际上从未被触发过。您应该检查第一个示例是否实际上触发了任何代码。