Guide to incorporating .js file components into routes for a router

Starting my journey with VueJS, I encountered a roadblock when trying to incorporate components in routes for a router.

This is the component:

export default Home = {
  template: `
    <div class="top_container">
        <div class="left_container">
            <div class="title">
                <h1>Current Settings</h1>
            </div>
            <div class="inner_container">
                <p>URL: <span><?php if(isset($arrayInputs[0])) echo $arrayInputs[0]; ?></span></p>
                <p>URL Refresh Interval: <span><?php if(isset($arrayInputs[1])) echo $arrayInputs[1]; ?></span>(s)</p>
                <p>Brightness: <span><?php if(isset($arrayInputs[2])) echo $arrayInputs[2]; ?></span>(&#37;)</p>
            </div>
        </div>

        <div class="right_container">
            <div class="title">
                <h1>Change Settings</h1>
            </div>
            <div class="inner_container">

            </div>
        </div>
    </div>
    `,
};

The primary app setup looks like this:

import "https://cdn.jsdelivr.net/npm/vue/dist/vue.js";
import "https://unpkg.com/vue-router/dist/vue-router.js";

import "./components/Navbar.js";
import Home from "./components/Home.js";

const router = new VueRouter({
  routes: [
    { path: '/', redirect: '/home' },
    { path: '/home', component: Home },
    // { path: '/dhcp', component: DHCP },
    // { path: '/static', component: Static },
    // { path: '/update', component: Update },
    { path: '*', component: NotFound }
  ]
})

new Vue({
  el: '#app',
  router: router,
})

Here is the HTML used:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="index.css">
    <script type="module" src="./src/App.js"></script>
    <title>Document</title>
</head>

<body>
    <div id="app">
        <Navbar></Navbar>
        <section>
            <transition name="fade" mode="out-in">
                <router-view></router-view>
            </transition>
        </section>
    </div>
</body>

</html>

An error I am facing is:

Home.js:1 Uncaught ReferenceError: Home is not defined

In what way am I possibly misunderstanding?

I comprehend that I can generate an HTML element from a component using:

Vue.component("Home", { ... });

similarly how I did with <Navbar></Navbar>, but my requirement is to utilize them as components within routes and not merely as HTML tags.

Answer №1

The issue you're encountering is due to the reference error related to the word Home in the initial line of Home.js. To resolve this problem, ensure that your Home component is structured as follows:

export default {
    name: "Home",
    ...

Answer №2

let's consider removing the Home component and see if that helps.. the instructions provided above outline the process of creating a separate routes.js file and offer guidance on writing routes and importing components

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

Attempting to discover the secret to keeping a hamburger menu fixed in place once it has been expanded

Exploring this example https:// codepen.io/ducktectiveQuack/pen/mPGMRZ I had trouble understanding the code block, so I resorted to trickery (just remove the space between the '/' and the 'c' lol) My goal is to have the hamburger men ...

Believing in false promises as true is what the statement assumes

I'm working on authentication for my app and encountered the following code: const ttt = currentUser.changedPasswordAfter(decoded.iat); console.log(ttt); if (ttt) { console.log('if thinks ttt is true'); The changedPasswordAfter fu ...

Tips for avoiding API calls at specific intervals while in the process of logging out from a web application

I have integrated a 60 second timer observable in my Ionic/Angular app, which emits the current time synchronized with the server time. Every minute, I fetch permissions, settings, and other data by passing a token with each request. Upon logout, I revoke ...

Assigning a buffer to a createReadStream: A step-by-step guide

Based on the official documentation, createReadStream has the capability to accept a buffer type as the path argument. However, most Q&A resources only provide solutions on how to pass arguments as a string, rather than a buffer. How can I correctly set ...

Learn how to display two different videos in a single HTML5 video player

Seeking a solution to play two different videos in one video element, I have found that only the first source plays. Is jQuery the answer for this problem? HTML Code: <video autoplay loop id="bbgVid"> <source src="style/mpVideos/mpv1.mp4" type ...

Cannot upload pictures using pixi.js PIXI.Texture.from()

I'm currently developing a web game using React with PixiJS. I am trying to incorporate images from my local directory into Pixi.js. For reference, I found this helpful website: Here are the snippets of code that I have used: import * as PIXI from & ...

Can you show me how to access the elements of a JSON object named "foo.txt" and print them out?

Currently, I am working with JavaScript and JSON. My goal is to retrieve data from an API where objects contain specific details. Specifically, I need to display the details of an object named "foo.txt" which includes elements such as size, raw_url, conten ...

How can you ensure a div stays at the top or bottom of a page based on the user's scrolling behavior?

Hello there! While I know there have been many questions regarding sticking a div to the top or bottom while scrolling, my particular issue is a bit more specific. My dilemma is that I am looking for the div to stick either to the top or the bottom based ...

An array becomes undefined once the previous array is removed

Consider the following code snippet: using the splice method, a specific item from Array1 is retrieved and stored in a variable called Popped. Next, Popped is added to array2. However, if we then delete the value from Popped, why does array2 become undef ...

Child component in Angular2 makes an observer call to its parent object

Let me try to explain this in the best way possible. I have a service that includes an observable class responsible for updating itself. This observable class needs to be pushed out to the app using the observer within the service. How can I trigger that ...

What is preventing the Delete icon button from being associated with the <select> element in this particular situation?

Here is an HTML markup snippet for a <table>: <table id="blacklistgrid_1" class="table table-bordered table-hover table-striped"> <thead> <tr> <th style="vertical-align:middle">Products</th> ...

A guide to iterating over a basic JSON structure using JavaScript

While there are similar inquiries on this topic within the site, they all involve arrays nested inside other arrays. I am struggling with a simpler issue and need some guidance. The JSON data is being produced by a PHP file and appears like this when retr ...

What methods can be used to control the URL and back button in a web application designed similar to an inbox in Gmail?

Similar Question: Exploring AJAX Techniques in Github's Source Browser In my application, there are essentially 2 main pages: The main page displays a list of applications (similar to an inbox) The single application page is packed with various ...

implement a dropdown feature for a vertical menu with the help of Jquery

Struggling to implement a dropdown feature on a vertical navigation using Jquery. The HTML includes a nav section with 1st level list items and nested li's for second level menu items. On clicking the 1st level li, the intention is to toggle SHOW/HID ...

The Socket.io and express app are facing connectivity issues as a result of a CORS error stating: "It is not allowed to use the wildcard '*' in the 'Access-Control-Allow-Origin' header"

I'm going crazy over a trivial issue I've encountered. My socket.io/express app is deployed on Digital Ocean using Docker setup. To enable https, I'm utilizing Caddy within my Docker setup for automatic https. I've been attempting to ...

What is the best way to input information into my Google spreadsheet with React JS?

After using https://github.com/ruucm/react-google-sheets as a reference, I encountered a persistent gapi 404 error whenever I tried to run the code. It seems like the GitHub link might not exist, causing my app to fail. However, I could be mistaken. Is t ...

Angular Universal 9 disrupts the functionality of Bootstrap CSS directives

My application runs perfectly fine with npm run start. However, when I try npm run build:ssr and npm run serve:ssr, it doesn't function properly without throwing any errors. While running npm run start, there's a button with 65% opacity. The des ...

What is the best approach for transmitting data to the post method of Node.js using AJAX/jQuery?

A UDP server I have is set up to respond with a different message each time it receives a message. When I hard code the message into the variable "message," everything works fine. However, I want the client to be able to manually type in a message, and t ...

What are some ways to conceal or deactivate the JSON response in the browser when using the $http.post method in AngularJS

I am looking for a way to protect my json response data using angularjs $http.post("./rest/getMethodBack", parameter).then(function(response){ console.log(response); }); When viewed in the browser console, the output will appear as: {"name": ...

Deceptive scope dilemma?

Seems simple enough, but there's a glitch in the system. $(function(){ (function(){ /** * @return boolean Based on success */ function saveDataOnServer(data){ var success = false; $.ajax({ url : ...