Having trouble loading a component in VueJS with router in Vue.js 3?

After clicking on a router-link to navigate to the register-form page, I noticed that the URL changed but the component did not load properly. https://i.sstatic.net/qkKBH.jpg

Initially, I suspected an issue with the navbar being within a component, but that was not the root cause of the problem...

Take a look at the code snippet responsible for defining the routes in the router file:

    import {createRouter, createWebHashHistory} from 'vue-router'

const routes = [
    {
        path: '/',
        name: 'Home',
        component: () => import(/* webpackChunkName: "home" */ '../views/Home.vue')
    },
    {
        path: '/formulario-registro',
        name: 'RegisterForm',
        component: () => import(/*webpackChunkName: "registerform"*/ '../views/RegisterForm.vue')
    }

]

const router = createRouter({
    history: createWebHashHistory(),
    routes
});

export default router

Furthermore, let's examine the nav component where the router-links are located:

  <div class="nav">
<div class="brand">
  <router-link to="/">BookArt</router-link>
</div>
<div class="collapse">
  <span id="mobile-icon" v-on:click="responsiveNavbar"></span>
</div>
<div class="links">
  <ul id="nav-list-group">
    <li class="list-item">
      <router-link to="/"> Home</router-link>
    </li>
    <li class="list-item">
      <router-link to="/formulario-registro"> Register</router-link>
    </li>
    <li class="list-item">
      <router-link to=""> Login</router-link>
    </li>
  </ul>
</div>

Additionally, here is the main.js code for reference:

    import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'

createApp(App).use(store).use(router).mount('#app')

Moving on to the App.vue code:

 <template>
  <Nav></Nav>
  <router-view/>
</template>

<script>

import Nav from '@/components/Nav.vue'

export default {
  components: {
    Nav
  }
}
</script>

Last but not least, let's review the register-form component's code:

   <template>
  <form action="">
    <div class="form-group">
      <input type="text" name="form.username" id="form.username" class="username" placeholder="Username....">
    </div>
    <div class="form-group">
      <input type="file" name="form.profile_pic" id="form.profile_pic" class="profile_pic"
             placeholder="Profile Picture....">
    </div>
    <div class="form-group">
      <input type="email" name="form.email" id="form.email" class="email" placeholder="Email....">
    </div>
    <div class="form-group">
      <input type="password" name="form.password" id="form.password" class="password" placeholder="*******">
    </div>
    <div class="form-group">
      <input type="password" name="form.confirm_password" id="form.confirm.password" class="confirm_password"
             placeholder="*******">
    </div>
    <div class="form-group">
      <button>Sign Up</button>
    </div>
  </form>

</template>

<script>
export default {
  name: "RegisterForm",

  mounted() {
    console.log('Registration form loaded successfully');
  }

}
</script>

Answer №1

The problem lies within the ../view/RegisterForm component, as it renders itself:

<template>
  <RegisterForm></RegisterForm><!-- this is the component itself not the child one-->
</template>

<script>
import RegisterForm from '@/components/Register-form';
export default {
  components: {
    RegisterForm
  },
  name: "RegisterForm"
}
</script>

<style scoped>
</style>

This creates an infinite loop, and can be resolved by simply changing the name of the imported component:

<template>
  <RegisterForm1></RegisterForm1>
</template>

<script>
import RegisterForm1 from '@/components/RegisterForm1';
export default {
  components: {
    RegisterForm1
  },
  name: "RegisterForm"
}
</script>

<style scoped>
</style>

Answer №2

modification in App.vue =>

<template>
  <router-view />
</template>

<template>
  <router-view :key="$route.path" />
</template>

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

Angular 4, Trouble: Unable to resolve parameters for StateObservable: (?)

I've been working on writing unit tests for one of my services but keep encountering an error: "Can't resolve all parameters for StateObservable: (?)". As a result, my test is failing. Can someone please help me identify and fix the issue? Here& ...

Automatic resizing of line charts in Angular with nvd3

I'm currently utilizing AngularNVD3 directives. Referencing the example at: https://github.com/angularjs-nvd3-directives/angularjs-nvd3-directives/blob/master/examples/lineChart.with.automatic.resize.html <!-- width and height have been removed f ...

Incorporating external resources into Laravel

Though it may be an old question, I have never attempted it before and have been unable to find a solution (all the samples I found were in scss files). Currently, I am using JavaScript scaffolding as my front-end, so all I have in my layout assets is: & ...

Vue Selecting Several Options

I am looking to implement multiple selections without using the multiple.vue library. I want to create my own solution. In JavaScript, I have data structured like this: data: roles : [here data] form.roles: [] And here is how I am handling it in m ...

Specify the CSS bundle during the compilation of a Vue application

I am faced with the challenge of using a single code-base for my Vue application, but needing to compile it with different styles depending on the end user. Each end user (which in this case refers to a group or organization) has their own specific CSS fil ...

Problems with Vuex getter reactivity when used in conjunction with Vue router

I've encountered an issue with my Vuex getter that fetches data for the current route and displays it in a Vuetify v-data-table. Everything works perfectly fine when the component is initially created. However, when I add a new entry to the data array ...

A step-by-step guide on accessing the data from an uploaded JSON file in a React application

One exciting feature is the drag and drop component that allows users to add multiple files. However, there seems to be an issue with displaying the content of a JSON file once it's added. Below is the code snippet in question: if (files?.length) ...

Encountering a 400 Status Error in Shopware stating "The value provided is too lengthy. Please limit it to 255 characters or less" when attempting to update a database table

Whenever I attempt to insert data into the Shopware 6 database table, I consistently receive a 400 status response along with the message This value is too long. It should have 255 characters or less. The field in question that I am trying to update, desc ...

Tips for executing specific javascript on small screens or mobile devices

I am currently in the process of developing a Vue web application that needs to be functional on all devices. I have certain code that should only run on small screens or mobile devices. Right now, I am using an if statement with $(window).width() to achie ...

Utilizing replace and regex in jQuery to add a space before a capitalized character within a word

these are the elements in the array WorkNumber WorkType Version Status Module Priority AssignedBy AssignedTo Subject Details EstimatedTime ActualTime CreatedDate ModifiedDate i would like the ou ...

Steps for generating a dropdown menu using API JSON information

I'm new to using Webapi with AngularJS. I have a URL that returns data in JSON format, and I want to extract only the employee names from the data and display them in a dropdown list using AngularJS. Any assistance would be greatly appreciated. ...

Using Electron to Show a Video Stored in the Local File System Using a Custom Protocol

Currently, I'm facing challenges while using electron to develop a basic video display application. Despite my efforts, I am struggling to show a video in the renderer by correctly implementing the registerSchemesAsPrivileged method. Although there ar ...

The dialog box is not taking up the full width of the browser window

I'm facing an issue with a dialog box that only occupies a portion of the browser width, despite having a width set to 100%. The backdrop, however, extends across the entire width. //App.js import React from "react"; import ConfirmationDial ...

"Encountering issues with logging in through AngularJS and the $http request functionality

My goal is to login using $http and GET of REST web services. This is my approach: Retrieve data based on username and password using $http.get Store the result in $scope.getResult=res; Assign variables to the retrieved data: var result=$scope.getResult ...

Tips for effectively utilizing Mongoose models within Next.js

Currently, I am in the process of developing a Next.js application using TypeScript and MongoDB/Mongoose. Lately, I encountered an issue related to Mongoose models where they were attempting to overwrite the Model every time it was utilized. Here is the c ...

Receiving data from multiple sockets in Node.js with Socket.io

I recently started working with Node.js to develop an online game that acts as a server-side application. This application serves the .html and .js files to the client while managing the game's logic. I'm utilizing Socket.io for communication bet ...

What could be the reason behind the failure of this :after element?

I am facing an issue with the preloader on my webpage where the animation is not displaying as expected. The animation should appear on top of a dark black background before the page fully loads, but it seems to be missing. The CSS for the animation works ...

What is the most effective way to determine which radio button is currently selected in a group with the same name using JQuery?

<form class="responses"> <input type="radio" name="option" value="0">False</input> <input type="radio" name="option" value="1">True</input> </form> Just tested: $('[name="option"]').is(':checked ...

Updating a value using jQuery AJAX techniques

Using jQuery AJAX, I am loading the content of a page in this way: $(document).ready(function(){ $('#next').click(function(event){ $.ajax({ url: "load.php?start="+$('#lastid').text(), success: function(html){ $("#results"). ...

Receiving server data with socket.io in Node.js

I have set up a Node.js server to send data to an HTML client using socket.io: var spawn = require('child_process').spawn; var child = spawn('node', ['file.js']); child.stdin.write("Hello there!"); child.stdout.on(&apo ...