Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript meteorjs中的重定向路由_Javascript_Backbone.js_Meteor_Handlebars.js - Fatal编程技术网

Javascript meteorjs中的重定向路由

Javascript meteorjs中的重定向路由,javascript,backbone.js,meteor,handlebars.js,Javascript,Backbone.js,Meteor,Handlebars.js,所以我想在meteor.js中创建一个稍微.ly类型的站点。我想不出如何重定向到下一页。我使用backbone.js进行路由,这些路由正在运行。理想情况下,它会从数据库中获取链接,创建链接并重定向到它。我尝试了window.location,但无法正常工作 js文件: html: 我的应用程序名称 {{>主页} {{>帮助} {{{#如果主页} 主页 {{/if} {{{#如果帮助页面} 帮助页 {{/if} 使用 如果要运行更新会话变量的router方法,则为true。我已修改了html模板

所以我想在meteor.js中创建一个稍微.ly类型的站点。我想不出如何重定向到下一页。我使用backbone.js进行路由,这些路由正在运行。理想情况下,它会从数据库中获取链接,创建链接并重定向到它。我尝试了window.location,但无法正常工作 js文件:

html:


我的应用程序名称
{{>主页}
{{>帮助}
{{{#如果主页}
主页
{{/if}
{{{#如果帮助页面}
帮助页
{{/if}
使用


如果要运行更新会话变量的router方法,则为true。我已修改了html模板,以帮助解释如何使用Backbone.history.navigate重定向。我添加了两个额外的模板,名为content和about,以及3个指向三条路径home、help和about的静态链接。内容取决于我们的模板帮助者主页、帮助页或aboutPage返回的内容

<head>
 <title>My app name</title>
</head>

<body>
 <a href='/'>Home</a>
 <a href='/help'>Help</a>
 <a href='/about'>About</a>
 {{> content}}
</body>

<template name='content'>
{{#if homePage}}
    {{> home}}
{{/if}}

{{#if helpPage}}
    {{> help}}
{{/if}}

{{#if aboutPage}}
    {{> about}}
{{/if}}
</template>

<template name="home">
  <h1>Home Page</h1>
</template>

<template name="help">
    <h1>Help Page</h1>
</template>

<template name="about">
    <h1>About Page</h1>
</template>

导航到外部url。您可以在路由器上方导航

if (Meteor.isClient) {
 var Router = Backbone.Router.extend({
 routes: {
  "" : "main",
  "help" : "help",
  'about' : "about",
 },
 navigate: function (url) { window.location = url; },
 main: function() {
  Session.set('currentPage', 'homePage');
 },
 help: function() {
  Session.set('currentPage', 'helpPage');
 },
 about: function() {
  Session.set('currentPage', 'about');
 }
});

var app;
Meteor.startup(function () {
 app = new Router;
 Backbone.history.start({pushState: true});
});
Template.content.homePage = function(){
 return Session.get("currentPage") == 'homePage';
};
Template.content.helpPage = function(){
 return Session.get("currentPage") == 'helpPage';
};
Template.content.aboutPage = function(){
 return Session.get("currentPage") == 'about';
};

//I will add a helper below that will redirect to google everytime about link is     clicked. Open console to see message logged before redirect

Template.about.rendered = function(){
 console.log('About is about to be rendered but wait..... we redirect to google.com');
 app.navigate('http://google.com');
};

你能进一步说明一下吗,我对meteor/backbone还相当陌生。也许是一个重定向的例子?这是可行的,但当我试图将其引导到异地时就不行了<代码>主干。历史记录。导航(“http://google.com“,对)转到:
localhost:3000/http://google.com
。您将如何导航到其他域?我将添加另一个答案如果您不希望覆盖导航,则只需使用此
window.location.href=http://google.com';
Backbone.history.navigate('/help', trueorfalse);
<head>
 <title>My app name</title>
</head>

<body>
 <a href='/'>Home</a>
 <a href='/help'>Help</a>
 <a href='/about'>About</a>
 {{> content}}
</body>

<template name='content'>
{{#if homePage}}
    {{> home}}
{{/if}}

{{#if helpPage}}
    {{> help}}
{{/if}}

{{#if aboutPage}}
    {{> about}}
{{/if}}
</template>

<template name="home">
  <h1>Home Page</h1>
</template>

<template name="help">
    <h1>Help Page</h1>
</template>

<template name="about">
    <h1>About Page</h1>
</template>
if (Meteor.isClient) {
var Router = Backbone.Router.extend({
  routes: {
    "" : "main",
    "help" : "help",
    'about' : "about",
  },
  main: function() {
    Session.set('currentPage', 'homePage');
  },
  help: function() {
    Session.set('currentPage', 'helpPage');
  },
  about: function() {
    Session.set('currentPage', 'about');
  }
});

Meteor.startup(function () {
  var app = new Router;
  Backbone.history.start({pushState: true});
});
Template.content.homePage = function(){
  return Session.get("currentPage") == 'homePage';
};
Template.content.helpPage = function(){
  return Session.get("currentPage") == 'helpPage';
 };
Template.content.aboutPage = function(){
  return Session.get("currentPage") == 'about';
};

//I will add a helper below that will redirect to homePage everytime about link is clicked. Open console to see message logged before redirect

Template.about.rendered = function(){
  console.log('About is about to be rendered but wait..... we redirect to home');
  Backbone.history.navigate( "/", true);
};
}
if (Meteor.isClient) {
 var Router = Backbone.Router.extend({
 routes: {
  "" : "main",
  "help" : "help",
  'about' : "about",
 },
 navigate: function (url) { window.location = url; },
 main: function() {
  Session.set('currentPage', 'homePage');
 },
 help: function() {
  Session.set('currentPage', 'helpPage');
 },
 about: function() {
  Session.set('currentPage', 'about');
 }
});

var app;
Meteor.startup(function () {
 app = new Router;
 Backbone.history.start({pushState: true});
});
Template.content.homePage = function(){
 return Session.get("currentPage") == 'homePage';
};
Template.content.helpPage = function(){
 return Session.get("currentPage") == 'helpPage';
};
Template.content.aboutPage = function(){
 return Session.get("currentPage") == 'about';
};

//I will add a helper below that will redirect to google everytime about link is     clicked. Open console to see message logged before redirect

Template.about.rendered = function(){
 console.log('About is about to be rendered but wait..... we redirect to google.com');
 app.navigate('http://google.com');
};