我在lib/server/plugins.js
Meteor.methods({
getPlugins: function() {
return [
{ path: 'test' },
{ path: 'test2' }
]
}
});
和lib/routes.js
Router.route('/', function() {
this.render('home');
});
Meteor.call('getPlugins', function(e,r) {
if(!e) {
for(var plugin in r) {
function() {
this.route(r[plugin].name);
})
}
} else {
console.log(e);
}
})
var routes = [
{ path: '/test3' },
{ path: '/test4' }
]
for(var i in routes) {
Router.map(function() {
this.route(routes[i].path);
});
}
本地变量路由中的所有路由都正常,但来自getPlugins
铁路由器的路由说Oops, looks like there's no route on the client or the server for url: "http://localhost:3000/test2."
答案 0 :(得分:0)
试试这个,首先添加一个/之前的路线:
Meteor.methods({
getPlugins: function() {
return [
{ path: '/test' },
{ path: '/test2' }
]
}
});
然后将此this.route(r[plugin].name);
修改为Router.route(r[plugin].path)
答案 1 :(得分:0)
感谢Kyll我想出了这个解决方案,它完成了这项工作,但我仍然对子路径有疑问
Router.route('/:plugin', function() {
var that = this;
Meteor.call('getPlugins', function(e,r) {
if(!e) {
for(var plugin in r) {
if(r[plugin].path == that.params.plugin) {
that.render(that.params.plugin);
}
}
} else {
console.log(e);
}
})
});