Guide to showcasing stationary HTML documents using iron router

Is there a way for me to display regular HTML files using Iron Router? I've been trying, but it keeps showing me a different template instead of the one I'm trying to attach with Iron Router.

This is the layout I am working with:

<template name="mainLayout">

{{> yield region="navBar"}}

{{> yield}}

{{> yield region="footer"}}

</template>

Here's how my router.js file is set up:

Router.route('/',{
  name: 'root',
  controller: 'MainPageController'
});
Router.route("/:_id",{
  name: 'signlePost',
  controller: 'singlePostController'
});

Router.route("/about", function(){
  this.render("aboutUs")
});

Below is the template I want to render:

<template name="aboutUs">
  <p>
    Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
  </p> 
</template>

However, instead of displaying the aboutUs page, it keeps rendering the singlePost template on the aboutUs page. Can someone please assist me with this issue?

Answer №1

There may be different ways to tackle this issue, but one potential solution is as follows:

  1. To begin, create a controller called about_us_controller.js to handle your html file.

    this.AboutController = RouteController.extend({
    template: "aboutUs",
    action: function() {
       this.render();
    }
    });
    
  2. Next, make sure to declare it in your router.js

    Router.map ( function () {

    this.route("aboutUs", {path: "/about", controller: "AboutController"});

    //include any other necessary routes
    });

Note: Apologies if the code formatting appears incorrect.

  1. After completing the above steps, you can now access your 'aboutUs' template using something like {{pathFor 'aboutUs'}}, which can be handy for generating links with a href attribute.

Answer №2

Consider changing the order in which the routes are declared, as the signlePost route pattern also matches "/about".

Router.route("/:_id",{
    name: 'signlePost',
    controller: 'singlePostController'
});
Router.route("/about", function(){
    this.render("aboutUs")
});

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Encountering a parsing issue within my React program

I keep encountering a parsing error while trying to run my React application The compilation fails with the following error message: ./src/App.js Line 7: Parsing error: Unexpected token, expected "{" After reviewing my code, I couldn't find any unex ...

Converting a serialized form to JSON with a list of tags: A step-by-step guide

Below is the form structure: <form> <input type="text" value="value1a" name="parentobject.childobject[0].field1"/> <input type="text" value="value2a" name="parentobject.childobject[0].field2"/> <input type="text" value="value3a" na ...

Occasionally, updating state within useEffect can lead to an inaccurate state value

My latest project involves building a chat application using React and socketio. I've encountered an issue with the useEffect function that handles incoming messages: useEffect(() => { socket.on("new-message", () => { setMessages ...

Is there a way to make my for loop search for the specific element id that I have clicked on?

When trying to display specific information from just one array, I'm facing an issue where the for loop is also iterating through other arrays and displaying their names. Is there a way to only show data from the intended array? const link = document. ...

Conceal the object, while revealing a void in its place

Is there a way to hide an image but keep the containing div blank with the same dimensions? I want it to appear as if no content was there, maintaining the original width and height. For example: http://jsfiddle.net/rJuWL/1/ After hiding, "Second!" appea ...

Why does serializing a JavaScript Object to JSON result in "{}"?

Hello fellow developers, I'm currently working on setting up a LocalStorage feature for my web application. One issue I've come across is that all objects in the Model abstraction layer need to be serialized. I understand that functions aren&a ...

The radio button allows for the selection of multiple items, rather than just one at a time

https://i.sstatic.net/9MEzS.png I have implemented a radio input as shown below <input type="radio" id={el.name} className="form-check-input" name={el.name} data-count={el.name} value={el.id} onChange={this.select_role.bind(this)} style={{margin: "4px ...

In backbone.js, I often encounter the issue where my attributes are saved as nil when I create a

Whenever I try to add a new affiliate, the information is saved in the database but without a name. I have been struggling to fix this issue for quite some time now. class Shop.Views.AffiliatesNew extends Backbone.View template: JST['affiliates/ne ...

Maintaining the dropdown in the open position after choosing a dropdown item

The dropdown menu in use is from a bootstrap framework. See the code snippet below: <li id="changethis" class="dropdown"> <a href="#" class="dropdown-toggle" data-toggle="dropdown>LINK</a> <ul class="dropdown-menu"> <li id ...

Send JavaScript variable using a query parameter

I am working on passing a JavaScript variable across all pages in my project. The goal is to calculate the total value from various pages and display it at the end of navigation. Below is an example of my JS code: <script> $(document).ready ...

Husky 5: The Ultimate Gitignore Manager

Last week, a new version of Husky was released, known as Husky 5. I came across an interesting article discussing the features and updates in this release that can be found here. Upon migrating to Husky 5 (), I discovered a new directory named .husky with ...

Return to the initial stage of a multistep process in its simplest form following a setTimeout delay

I recently customized the stepsForm.js by Copdrops and made some modifications. Although everything works well, I'm struggling to navigate back to the initial step (first question) after submitting the form due to my limited knowledge of JavaScript. ...

Ways to ascertain if a view has completed rendering in JavaScript

I am currently building my application using the awesome backbone.js framework. Within my code, I have this layoutView that handles rendering the overall layout and also includes a smaller profile section. The dilemma I'm facing is with the timing o ...

Tips for horizontally arranging a list with a flexible number of columns

I am attempting to create a horizontal list with 3 columns that automatically moves to a new line when the columns are filled. I have been trying to implement this using PHP but haven't had any success. If anyone could provide some guidance on how to ...

Resizing an image with six corners using the canvas technique

Currently, I am facing two issues: The topcenter, bottomcenter, left and right anchors are not clickable. I'm struggling with the logic to adjust the image size proportionally as described below: The corner anchors should resize both height and wi ...

Is mobile support available for the redips drag and drop library?

Currently working on a Worklight project where I am developing a hybrid application. I am interested in incorporating drag and drop functionality similar to what is offered by the redips drag and drop library. If you would like more information about the ...

Creating a nested structure for dynamic data in Angular

I'm facing an issue while attempting to create a flexible structure dynamically. I possess the following string. "Client->Plant->Route->Turn" I have an array of devices with values for each field in the string along with extra information, ...

Understanding the reading of Java Class List in Vue Js

As a beginner in Front-end development, I am trying to figure out how I can use Vue.js to read a Java class List. Specifically, I have a Java class that includes a list of fruits and I want to be able to display this list on the UI using Vue.js: public c ...

Tips for personalizing error messages for the "required" field by utilizing a dictionary feature on VeeValidate in Vue.Js

I am trying to update the error message that appears when an input field with the "cpf" rule is left empty (meaning it does not meet the "required" rule). I believe using the "dictionary method" with custom messages is the solution, but I am struggling to ...

What is the best way to stop a web page from automatically scrolling to the top of the browser?

I am experiencing an issue on my webpage where, after scrolling down and selecting an item to view, pressing the browser back button causes the page to scroll back to the top instead of the previous location. The webpage is using JavaScript to render a l ...