admin管理员组文章数量:1278881
So I'm creating a basic vanity URL system, where I can have , grab an item from the database and redirect to a specific URL based on whether or not the client is mobile/desktop and other features.
I usually build Facebook apps, so in the case of desktop they would be redirected to a Facebook URL, otherwise on mobile I can just use normal routes.
Is there a way to redirect from Iron Router on the server-side to an external website?
this.route('vanity',{
path: '/v/:vanity',
data: function(){
var vanity = Vanity.findOne({slug:this.params.vanity});
// mobile / desktop detection
if(vanity){
if(mobile){
// Redirect to vanity mobile link
}else{
// Redirect to vanity desktop link
}
}else{
Router.go('/');
}
}
});
So I'm creating a basic vanity URL system, where I can have http://myURL./v/some-text
, grab an item from the database and redirect to a specific URL based on whether or not the client is mobile/desktop and other features.
I usually build Facebook apps, so in the case of desktop they would be redirected to a Facebook URL, otherwise on mobile I can just use normal routes.
Is there a way to redirect from Iron Router on the server-side to an external website?
this.route('vanity',{
path: '/v/:vanity',
data: function(){
var vanity = Vanity.findOne({slug:this.params.vanity});
// mobile / desktop detection
if(vanity){
if(mobile){
// Redirect to vanity mobile link
}else{
// Redirect to vanity desktop link
}
}else{
Router.go('/');
}
}
});
Share
Improve this question
asked Jan 18, 2015 at 22:03
ahrenahren
17k5 gold badges52 silver badges70 bronze badges
1 Answer
Reset to default 13Here is a simple 302-based redirect using a server-side route:
Router.route('/google/:search', {where: 'server'}).get(function() {
this.response.writeHead(302, {
'Location': "https://www.google./#q=" + this.params.search
});
this.response.end();
});
If you navigate to http://localhost:3000/google/dogs, you should be redirected to https://www.google./#q=dogs.
Note that if you would like to respond with a 302 to all request verbs (GET, POST, PUT, HEAD, etc.) you can write it like this:
Router.route('/google/:search', function() {
this.response.writeHead(302, {
'Location': "https://www.google./#q=" + this.params.search
});
this.response.end();
}, {where: 'server'});
This may be what you want if you are doing redirects for SEO purposes.
本文标签: javascriptMeteorIron Router external redirectionStack Overflow
版权声明:本文标题:javascript - MeteorIron Router external redirection - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741238505a2363500.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论