有人使用Iron-Router和Spiderable-404吗? 我需要一些完整的示例来向我展示如何添加元标记。
他们这样说:
if (Meteor.isClient) {
Meteor.Router.add({
'/': 'index',
'/a': 'a',
'/b': function() {
Spiderable.httpHeaders['X-Foo'] = 'bar';
return 'b';
},
'*': function() {
Spiderable.httpStatusCode = 404;
return 'notFound';
}
});
}
但是这在铁路由器中不起作用,并且在这个糟糕的例子中没有元标记,或者我无法使其工作,请帮助我填补空白。
答案 0 :(得分:2)
spiderable包只是你在Meteor中安装和忘记的包。您不能直接在您的应用中使用它。
流星SEO不是很成熟,但你可以选择基本的SEO工作。特别是当您使用铁路由器时,可以使用ms-seo智能包作为:$ mrt add ms-seo
然后在您的路由器配置中:
Router.map(function() {
return this.route('blogPost', {
path: '/blog/:slug',
waitOn: function() {
return [Meteor.subscribe('postFull', this.params.slug)];
},
data: function() {
var post;
post = Posts.findOne({
slug: this.params.slug
});
return {
post: post
};
},
onAfterAction: function() {
var post;
// The SEO object is only available on the client.
// Return if you define your routes on the server, too.
if (!Meteor.isClient) {
return;
}
post = this.data().post;
SEO.set({
title: post.title,
meta: {
'description': post.description
},
og: {
'title': post.title,
'description': post.description
}
});
}
});
});
对于404响应,铁路由器的标准notFoundTemplate
已经提供了开箱即用的HTTP状态码。对于其他状态代码,您需要定义server side routes
```` Router.map(function(){ this.route(' serverFile',{ 其中:'服务器', 路径:' / files /:filename',
action: function () {
var filename = this.params.filename;
this.response.writeHead(200, {'Content-Type': 'text/html'});
this.response.end('hello from server');
}
}); }); ````
PS:您可能需要参考此blog post和this one进一步阅读。
PPS:您的路由器配置看起来一般都是错误的。您的代码看起来像属于过时的流星路由器包。有关详细信息,请参阅iron-router package docs。