所以我想在meteor.js中創建一個bit.ly類型的站點。我無法弄清楚如何重定向關閉頁面。我使用backbone.js的路線,這是工作。理想情況下,它會從數據庫中獲取鏈接,創建鏈接並重定向到它。我試過了window.location但是,這並不正常工作 js文件:meteorjs中的重定向路由
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>
如果你不想重載導航,那麼只需使用這個'window.location.href ='http://google.com';' – jamin79