Page doesn't transition properly


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:

I have an HTML template (found here) that I’m chopping up into Blaze templates for integration into a real estate site that I’m working on. 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 /public folder. The files are loaded via regular <script> and <link> elements embedded in the <head> and near the bottom of the main layout.

Here is what my <head> looks like:

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

Here is what my main layout looks like:

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

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

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

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:

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

FlowRouter.notFound = {
  action() {
    BlazeLayout.render('app_home', { main: 'site_not_found' });

Right now almost all the links in the template don’t work since I haven’t swapped them out for ‘live’ {{pathFor 'route'}} 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 {{pathFor 'Site.home'}} 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!

Here is what the page looks like initially and after routing back home:

Before routing

After routing

Here are a couple of screenshots of my debugger highlighting the problem:

Before routing

After routing

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…

Does anyone have any idea how I can fix this?