铁:路由器通配符路径生成似乎被破坏

问题描述:

当您在iron中创建通配符URL:流星路径为模板助手,但也Router.go和Router.routes [routeName] .path()似乎被打破。铁:路由器通配符路径生成似乎被破坏

这是我们的路线:

Router.route('/:urlQuery*', function(){ 
    this.render('ourTemplate'); 
}, { 
    name : 'ourRoute', 
}); 

要访问生成的URL到这一点,我们尝试了以下内容:

Router.go('ourRoute', {urlQuery : 'test'}); 
Router.go('ourRoute', {urlQuery : ['test']}); 
Router.go('ourRoute', {urlQuery : null}); 
Router.go('ourRoute', {urlQuery : false}); 

Router.routes.ourRoute.path({urlQuery : 'test'}); 
Router.routes.ourRoute.path({urlQuery : ['test']}); 
Router.routes.ourRoute.path({urlQuery : null}); 
Router.routes.ourRoute.path({urlQuery : false}); 

和 - 当然 - 我们也尝试了{{pathFor}}模板-帮手。

每天的代码行抛出了同样的错误:

Uncaught Error: You are trying to access a wild card parameter at index 0 but the value of params at that index is undefined 

我没有发现在铁的任何参考:路由器指南所以我的问题是:如何产生铁网址:路由器用通配符作为参数?

+0

*上的/ *:urlQuery *是什么?我还没有看到,乐声就像你的混音参数和正则表达式? – FloatingCoder

+0

这是通配符的符号。因此,例如route/test1/test2会在urlQuery参数中保存“test1/test2”。 – TJR

+0

我以前从未见过。你是否想过正则表达式? http://*.com/questions/27455206/when-using-a-regex-in-iron-router-how-to-access-the-match –

看起来像铁路路由器使用path-to-regexp但用于铁路路由器的格式有点不同,并不是很清楚。试试这个...

Router.route('/:urlQuery(.*)', function(){ 

的()会告诉它采取帕拉姆名称,重复0次或更多次。只是urlQuery正在打破我想的名字,并使其成为正则表达式的一部分。现在,如果你想通过多张对象Router.go数组,你会有另外一个问题...

Router.go("our.route", {urlquery: ['test', 'another']}); 

产生类似如下的URL ...

http://localhost:3000/test%2Canother 

但是这另一个问题我还没有答案。也许在Router.go中发送多个,更好的方法是自己连接它们。看起来像铁路路由器和路径正则表达式尚未完全集成吗?