Meteor: Dynamic page not transitioning properly
<p>Okay, this is a really weird one. Unfortunately, I can't show a whole lot of code because I really have no idea where the problem is originating -- However, I can describe the problem. That said, if there' s some code you think is relevant, please ask and I'll post it! So, here goes:</p>

<p>I have an HTML template (found <a href="http://realplaces.inspirythemes.biz/" rel="nofollow noreferrer">here</a>) that I'm chopping up into Blaze templates for integration into a real estate site that I'm working on using Meteor. The template includes all these external CSS and JavaScript files that I've included by simply leaving the templates as-is and putting all the assets required by the template into <code>/public</code> folder of the Meteor project. The files are loaded via regular <code>&lt;script&gt;</code> and <code>&lt;link&gt;</code> elements embedded in the <code>&lt;head&gt;</code> and near the bottom of the main layout.  </p>

<p>Here is what my <code>&lt;head&gt;</code> looks like: </p>

<pre><code>&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;meta http-equiv="X-UA-Compatible" content="IE=edge"&gt;
    &lt;meta name="viewport" content="width=device-width, initial-scale=1"&gt;
    &lt;title&gt;Real Places&lt;/title&gt;
    &lt;link rel="icon" href="images/cropped-ms-icon-310x310-32x32.png" sizes="32x32" /&gt;
    &lt;link rel="icon" href="images/cropped-ms-icon-310x310-192x192.png" sizes="192x192" /&gt;
    &lt;link rel="apple-touch-icon-precomposed" href="images/cropped-ms-icon-310x310-180x180.png"&gt;
    &lt;!-- Google font--&gt;
    &lt;link href='http://fonts.googleapis.com/css?family=Varela+Round' rel='stylesheet' type='text/css'&gt;
    &lt;link href='https://fonts.googleapis.com/css?family=Roboto:400,300,300italic,400italic,500,500italic,700,700italic,900' rel='stylesheet' type='text/css'&gt;
    &lt;link href='https://fonts.googleapis.com/css?family=Dosis:400,700,600,500' rel='stylesheet' type='text/css'&gt;
    &lt;!-- Include the flexslider stylesheet --&gt;
    &lt;link href="js/flexslider/flexslider.css" rel="stylesheet"&gt;
    &lt;!-- Include the lightslider stylesheet --&gt;
    &lt;link href="js/lightslider/css/lightslider.min.css" rel="stylesheet"&gt;
    &lt;!-- Include the owl-carousel stylesheet --&gt;
    &lt;link href="js/owl.carousel/owl.carousel.css" rel="stylesheet"&gt;
    &lt;!-- Include the swipebox stylesheet --&gt;
    &lt;link href="js/swipebox/css/swipebox.min.css" rel="stylesheet"&gt;
    &lt;!-- Include the select2 stylesheet --&gt;
    &lt;link href="js/select2/select2.css" rel="stylesheet"&gt;
    &lt;!-- Include the font-awesome stylesheet --&gt;
    &lt;link href="css/font-awesome.min.css" rel="stylesheet"&gt;
    &lt;!-- Include the select2 stylesheet --&gt;
    &lt;link href="css/animate.css" rel="stylesheet"&gt;
    &lt;link href="js/magnific-popup/magnific-popup.css" rel="stylesheet"&gt;
    &lt;!-- Main stylesheet --&gt;
    &lt;link rel="stylesheet" href="css/main.css"/&gt;
    &lt;!-- Default Theme stylesheet --&gt;
    &lt;link rel="stylesheet" href="css/theme.css"/&gt;
&lt;/head&gt;
</code></pre>

<p>Here is what my main layout looks like: </p>

<pre><code>&lt;template name="app_home"&gt; &lt;!-- note this is distinct from site_home, which is a different template --&gt;
  &lt;body class="inspiry-slider-two"&gt;
    {{&gt; page_loader}}
    {{&gt; mobile_header}}
    {{&gt; site_header}}
    {{&gt; Template.dynamic template=main}}
    {{&gt; site_footer}}
    {{&gt; login_modal}}
    {{&gt; real_places_includes}}
  &lt;/body&gt;
&lt;/template&gt;
</code></pre>

<p>All of the scripts that the template depends on are inserted via the <code>real_places_includes</code> template call. Here is what this template looks like: </p>

<pre><code>&lt;template name="real_places_includes"&gt;
  &lt;script src="js/jquery-1.12.3.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/flexslider/jquery.flexslider-min.js"&gt;&lt;/script&gt;
  &lt;script src="js/lightslider/js/lightslider.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/select2/select2.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/owl.carousel/owl.carousel.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/swipebox/js/jquery.swipebox.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.hoverIntent.js"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.validate.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.form.js"&gt;&lt;/script&gt;
  &lt;script src="js/transition.js"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.appear.js"&gt;&lt;/script&gt;
  &lt;script src="js/modal.js"&gt;&lt;/script&gt;
  &lt;script src="js/meanmenu/jquery.meanmenu.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/jquery.placeholder.min.js"&gt;&lt;/script&gt;
  &lt;script src="js/custom.js"&gt;&lt;/script&gt;
  &lt;!-- .modal --&gt;
  &lt;script&gt;
     ...
     // This is a bunch of modal code specific to the template
     ...
  &lt;/script&gt;
&lt;/template&gt;
</code></pre>

<p>This works great when the page first loads, but when I route away from the main page and back, it appears as if assets aren't loading properly when I come back. Here is some relevant routing code:</p>

<pre><code>FlowRouter.route('/', {
  name: 'Site.home',
  action() {
    BlazeLayout.render('app_home', { main: 'site_home' });
  }
});

FlowRouter.notFound = {
  action() {
    BlazeLayout.render('app_home', { main: 'site_not_found' });
  }
};
</code></pre>

<p>Right now almost all the links in the template don't work since I haven't swapped them out for 'live' <code>{{pathFor 'route'}}</code> calls. So, if I say, click on one of those links, I get the 404 page, as I should. It appears to load just fine. On the 404 page, I added a <code>{{pathFor 'Site.home'}}</code> to navigate the user back to the main page. However, when you click it, all the page elements on the home page (the ones that previously loaded fine!) that depend on JavaScript don't seem to format correctly. I checked the Chrome debugger to find this out. However, all of the assets are still loaded properly according to Chrome's Resource inspector! </p>

<p>Here is what the page looks like initially and after routing back home: <br>
Before routing <br>
<a href="https://i.stack.imgur.com/P9zuU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/P9zuU.png" alt="enter image description here"></a><br>
After routing <br>
<a href="https://i.stack.imgur.com/AX19Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/AX19Q.png" alt="enter image description here"></a><br>
As you can see, the select boxes haven't been rendered properly, the slider at the top of the page below the nav bar also isn't rendering and displays an animated loading graphic... basically anything that depends on JavaScript is kaput.</p>

<p>Here are a couple of screenshots of my debugger highlighting the problem:<br>
Before routing<br>
<a href="https://i.stack.imgur.com/iKvdx.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iKvdx.jpg" alt="enter image description here"></a>
<br>
After routing<br>
<a href="https://i.stack.imgur.com/nMO9k.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nMO9k.jpg" alt="enter image description here"></a><br>
This is what that same 'Location' select looks like before and after using my route.</p>

<p>So, for whatever reason, when I hit some route, the code that the route depends on doesn't seem to execute as it should in order to format the page as it was originally HOWEVER if the route is hit when the site first loads, it executes fine... I feel like I need to be firing some global event or something like that manually, but I don't really know what... Or maybe something else entirely. I have tried firing <code>'load'</code> and <code>'ready'</code> events manually on the <code>Template.site_home.onRendered</code> callback, but that hasn't worked.  </p>

<p>Does anyone have any idea how I can fix this and make the page transition properly?</p>