ということで、meteor.jsでbit.ly系のサイトを作りたいと思います。ページ外にリダイレクトする方法がわかりません。機能しているルートに backbone.js を使用しました。理想的には、データベースからリンクを取得し、リンクを作成してリダイレクトします。window.location を試しましたが、正しく動作しません js ファイル:
if (Meteor.isClient) {
var Router = Backbone.Router.extend({
routes: {
"" : "main",
"/" : "main",
"help" : "help",
'help/' : "help",
},
main: function() {
Session.set('currentPage', 'homePage');
},
help: function() {
Session.set('currentPage', 'helpPage');
}
});
var app = new Router;
Meteor.startup(function () {
Backbone.history.start({pushState: true});
});
Template.home.homePage = function(){
return Session.get("currentPage") == 'homePage';
};
Template.help.helpPage = function(){
return Session.get("currentPage") == 'helpPage';
//I want to do a redirect here somewhere:
//window.location = 'http://google.com';
};
}
html:
<head>
<title>My app name</title>
</head>
<body>
{{> home}}
{{> help}}
</body>
<template name="home">
{{#if homePage}}
<h1>Home Page</h1>
{{/if}}
</template>
<template name="help">
{{#if helpPage}}
<h1>Help Page</h1>
{{/if}}
</template>