我有一个带参数的简单路线:
this.route('article', {
path: '/article/:_id',
data: function() { return Articles.findOne(this.params._id); }
});
Run Code Online (Sandbox Code Playgroud)
我想在这里使用带有_id的pathFor把手助手:
{{#each articles}}
<li><a href="{{pathFor 'article' _id}}">{{title}}</a></li>
{{/each}}
Run Code Online (Sandbox Code Playgroud)
这不适用于将_id标记传递到url中...
我刚开始在流星上使用铁路由器.我需要在主页上显示图像.我能够使用客户端路由为'home'配置路由.对于我尝试google的静态文件,发现添加服务器端路由可能有所帮助.所以,我在服务器的router.js上添加了以下代码.
Router.map(function() {
this.route('files', {
path: '/files/:path(*)',
action: function() {
var path = this.params.path;
console.log('will serve static content @ '+path);
this.response.sendfile(path);
}
});
});
Run Code Online (Sandbox Code Playgroud)
当我尝试访问时http://localhost:3000/files/someImage.png,它表示没有定义路由/files/someImage.png.难道我做错了什么?有没有其他方法使用铁路由器提供静态文件?
我想在网址中获取查询参数.
似乎没有一种简单的方法可以做到这一点......
这让我觉得我一定错过了文档中的某些内容.
我可以在模板中使用什么来找出route name与我当前所在路线相关的内容?
例如,如果我配置了这样的路线 iron-router
this.route('quick', {
path: '/wow/:_id',
template: 'create_question'
});
Run Code Online (Sandbox Code Playgroud)
因此,如果我在路线上,/wow/123我如何在模板中获取路由器的名称,在这种情况下如何quick进入我的模板?
我只是在寻找一个功能,我相信我可以使用一个把手助手来完成剩下的工作.我只需要一个函数来调用.
我在Meteor中使用内置的loginButtons选项,我想在用户登录后重定向.使用内置的网页代码段意味着我无法使用Meteor.loginwithPassword的回调,我看不到任何内部的钩子Iron-Router进行重定向.
有什么建议?
我正在努力解决如果用户没有登录而将用户重定向到登录页面的常见需求(Windows 7上的Meteor v0.8.0).
stackoverflow上有几个类似的问题,但似乎没有答案对我有用.
不会工作#1:render()
从文档:
onBeforeAction: function () {
if (!Meteor.user()) {
// render the login template but keep the url in the browser the same
this.render('login');
// stop the rest of the before hooks and the action function
this.stop();
}
},
Run Code Online (Sandbox Code Playgroud)
这里有两个问题:
1-文档已过时.没有this.stop()功能了.如前所述这里的代码应该是:
onBeforeAction: function (pause) {
if (!Meteor.user()) {
// render the login template but keep the url in the browser the same
this.render('login');
// stop the rest of the before …Run Code Online (Sandbox Code Playgroud) 自从将Meteor升级到1.0版以来,是否有其他人从Iron-Router收到以下错误?
如果您知道如何解决此问题,请在此处发布.
路线调度从未呈现.你忘记打电话
this.next()了onBeforeAction?
Router.map(function () {
Router.route('profileShow', {
waitOn: function () {
if (Meteor.user()) {
Meteor.subscribe('userData');
} else {
this.next();
}
},
data: function () {
if (Meteor.user()) {
return {profile: Meteor.user().profile};
}
}
});
});
Run Code Online (Sandbox Code Playgroud) 我的代码工作正常,直到昨晚,突然我收到此错误,路由根本无法正常工作.
middleware_stack.js:31Uncaught Error: Handler with name 'route' already exists.
Run Code Online (Sandbox Code Playgroud)
对于像这样的简单路线:
Router.route('/admin/dashboard', {
template:"adminDashboard"
});
Router.route('/admin/create/table', {
template:"create_table"
});
Run Code Online (Sandbox Code Playgroud)
我无法弄清楚错误,我检查了所有的路线.还有其他人遇到过这个错误吗?
我在流星应用程序中遇到了一个令人难以置信的荒谬错误.基本上,我有一个特定的页面,它会渲染一些模板,在Mac上崩溃Safari,而且只有Safari(并且只有当控制台未打开时).
我已经(稍微)将其缩小到一个似乎有助于解决问题的场景.删除下面列出的'floorList'模板上的事件处理.任何想法,问题和建议将不胜感激.
我知道很难说没有看到一切,但这里大致是设置:
我们正在使用铁路由器,主模板加载:
<template name="layout">
<div id="pageWrap">
{{> yield}}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
我们的"收益率"是一个模板:
<template name="pageList">
<div class="pages">
{{#each pageWithRank}}
{{> pageItem}}
{{/each}}
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
加载'pageItem'模板(限制返回10个项目)
<template name="pageItem">
<div class="page">
...
</div>
</template>
Run Code Online (Sandbox Code Playgroud)
以及包含帮助程序和事件处理程序的"pageItem"js文件,例如:
Template.pageItem.helpers({
...
});
Template.pageItem.events({
'click .shareable': function(e, template) {
...
},
'click .share': function(e, template) {
...
},
'click .removePage': function(e) {
...
}
});
Run Code Online (Sandbox Code Playgroud)
路由器配置:
var preloadSubscriptions = [];
preloadSubscriptions.push('notifications');
preloadSubscriptions.push('alerts');
preloadSubscriptions.push('myPages');
var mainYieldTemplates = {
'footer': { to: 'footer' },
'header': {to: 'header'}
};
Router.configure({ …Run Code Online (Sandbox Code Playgroud)