Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have modified your html template to help explain how to redirect using Backbone.history.navigate. I added two additional templates called content and about and 3 static links directing to three routes home, help and about. content depends on what our template helpers homePage, helpPage or aboutPage return</p> <pre><code>&lt;head&gt; &lt;title&gt;My app name&lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;a href='/'&gt;Home&lt;/a&gt; &lt;a href='/help'&gt;Help&lt;/a&gt; &lt;a href='/about'&gt;About&lt;/a&gt; {{&gt; content}} &lt;/body&gt; &lt;template name='content'&gt; {{#if homePage}} {{&gt; home}} {{/if}} {{#if helpPage}} {{&gt; help}} {{/if}} {{#if aboutPage}} {{&gt; about}} {{/if}} &lt;/template&gt; &lt;template name="home"&gt; &lt;h1&gt;Home Page&lt;/h1&gt; &lt;/template&gt; &lt;template name="help"&gt; &lt;h1&gt;Help Page&lt;/h1&gt; &lt;/template&gt; &lt;template name="about"&gt; &lt;h1&gt;About Page&lt;/h1&gt; &lt;/template&gt; </code></pre> <p>JS is now</p> <pre><code>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); }; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload