试图在我的流星应用程序的主路径(/)上使用params

时间:2014-04-24 09:44:56

标签: meteor iron-router

我试图在我的主要路线上使用参数。但实际上params没有设置,它们被用在路径中:

Router.map(function funcClientRouterMap(){
    this.route('home', {
        path: '/:_redirect?',
        action: function funcClientRouterMapAction(){
            console.log(this.path, this.params);
        }
        })
});

现在,如果我尝试手动重定向,这就是我得到的:

Router.go('home'); // it redirects on / => ok
Router.go('home', {_redirect: test}); // this.path = /test, and this.params is empty

我如何使用_redirect像params而不是路线?

由于

1 个答案:

答案 0 :(得分:0)

Router.go接受路径作为其第一个参数(根据docs)。因此,如果您尝试以编程方式导致与用户转到/redirectMeSomewhere相同的结果,则只需使用:

Router.go('/redirectMeSomewhere');

this.params._redirect应为'redirectMeSomewhere'

请注意,就像@apendua暗示的那样,如果你有其他路线,它可能会导致混乱的路由被定义为/:anything,因为其他路线可能永远不会被触发。如果上述操作无法解决问题,请尝试注释掉所有其他路线,看看是否有任何改变。