Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
正在尝试在我的meteor应用程序的主路径(/)上使用参数_Meteor_Iron Router - Fatal编程技术网

正在尝试在我的meteor应用程序的主路径(/)上使用参数

正在尝试在我的meteor应用程序的主路径(/)上使用参数,meteor,iron-router,Meteor,Iron Router,我想在我的主要路线上使用params。但事实上,参数未设置,它们在路径中使用: Router.map(function funcClientRouterMap(){ this.route('home', { path: '/:_redirect?', action: function funcClientRouterMapAction(){ console.log(this.path, this.params); }

我想在我的主要路线上使用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
如何像使用参数而不是路由一样使用_重定向


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

Router.go('/redirectMeSomewhere');
this.params.\u redirect
应该是
'redirectMeSomewhere'


请注意,正如@apendua所暗示的,如果您有其他路由,那么将路由定义为
/:anything
,可能会导致混乱,因为其他路由可能永远不会被触发。如果上述方法不起作用,请尝试对所有其他路由进行注释,看看是否有任何变化。

您的路由器中是否定义了其他路由?是的,我有几条路由,为什么?您说可能会很混乱,但事实上可能会很混乱,只有当参数的内容与一条路由相同时,我错了吗?实际上,this.params始终为空。我只需要做一个小项目来测试该功能。是否尝试从路线中删除
?所以只要
路径:'/:_重定向'