The RouterView component seems to be malfunctioning within the Vue project

I recently started working on a vue-project where I created a Home page with a sideBar component and a routerView component.

Here's a preview:

https://i.sstatic.net/f51tdsZ6.png

When clicking on any sidebar item, the router navigates to the corresponding path defined in the navigateToRoute() function in Home.vue. However, the components fail to render through the router-view, causing the sidebar to disappear upon redirection. This issue persists for other menu items as well. https://i.sstatic.net/rUWWbHMk.png

Below is the code snippet from Home.vue and router/index.js (where routes are defined).

Home.vue

<template>
  <div class="landing-page">
     <categoryPage v-if="menuItemRendered === 'category'" />

    <sidebar @menuItemSelected="navigateToRoute"/>


    <RouterView />

  </div>
</template>

... (remaining code is unchanged)

router/index.js

import Vue from 'vue'
import VueRouter from 'vue-router'
// Other imports...

const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

export default router

I suspect there might be an issue with how the route was defined, but I'm not entirely certain. I've already attempted some solutions, as noted below:

  • not working even though its connected
  • router-view content not rendering

Edit 1: Vue devtool image added

Upon visiting the homepage, this is what I observed in the Vue DevTools:

https://i.sstatic.net/1OmBX53L.png

Answer №1

Your App.vue file contains a router-view component, serving as the main router-view for all routes. This means that routes such as /company/:company_id/, /company/:company_id/subCategory, and others will be loaded into this router-view by default unless specified otherwise.

When dealing with nested routes (having a router-view inside another), you should utilize the children property within your routes:

const routes = [
  {
    path: '/company/:company_id/',
    name: 'Home',
    beforeEnter: routeGuard,
    component: Home,
    // SideBar Page routes
    children: [
      {
        path: 'category',
        name: 'category-page',
        component: CategoryPage,
      },
      {
        path: 'subCategory',
        name: 'subCategory',
        component: subCategory,
      },
      ...
    ]
  },


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

How can child components in ReactJS be conditionally rendered based on the status of userData loading?

It seems like there might be an issue with how we handle user login in our application. Whenever a user logs in, the redux state is updated with the server response. Many components rely on this logged-in status. We pass the currentUser object down to all ...

Locate a particular word in every element within an array range (angularjs)

I'm just getting started with learning angularjs and I would appreciate some kindness as a beginner. Currently, I am working on creating a poll app using angular. In my project, I have an array scope named items, which holds all the items to be adde ...

Retrieving data from a server using the GET method with parameters through axios in a React Native application

As someone new to Web requests, I have encountered a challenge that seems simple but has proven difficult for me. Despite searching the web, I am struggling to get a working response. When I input the URL 'http://www.test.com/callservice.php?action=s ...

What is the best way to sort ISO DateTime objects that fall outside of a particular time frame?

I'm currently working on a project that involves a list of objects with properties for startTime and endTime, all in ISO format. Here's a snippet of the list: list = [ { startTime: '2022-06-26T10:00:00.000Z', endTime: '2022- ...

rating-widget not displaying when performing an ajax request

Having an issue with the star rating plugin () while using an ajax function for searching and filtering. The star rating displays correctly when the page initially loads https://i.stack.imgur.com/eaOmu.png However, when utilizing the filter and search fu ...

Transforming Angularjs into Vuejs

I am currently transitioning a chat application from AngularJS to VueJS, but I am facing some challenges as I am not very familiar with AngularJS. Unfortunately, there is a lack of comprehensive resources available for me to gain a better understanding of ...

Navigating AJAX Pages - Maximize the Potential of #home and Other Sections

I am working on creating AJAX pages using a tutorial I found on Tutorialzine. The script I am using loads pages using AJAX but it requires specifying the page number in the URL like http://example.com/#page1 or http://example.com/#page2. Is there a way t ...

Update vue-table-2 to activate search filter upon button click, rather than keystrokes

exploring the capabilities of https://github.com/matfish2/vue-tables-2 using Vue.js version 2.6.11 Hey there! I'm a newbie developer delving into Vue.js after working in the React world. I'm aiming to modify the filter/search functionality to tr ...

Using Jquery to trim the data returned from the server response

Utilizing asp.net for obtaining the server response via JQuery AJAX in JSON format has been my approach. I've experimented with both JQuery.getJSON() and typical jQuery response methods, followed by conversion to JSON format using $.parseJSON. Howeve ...

Encountered a snag with submitting data via AJAX: received an error message stating

I created this custom script for a contact form on my website, and it seems to be working fine. However, I'm encountering an issue where instead of storing the data in my database, all I get is [object HTMLCollection]. Can someone please explain wh ...

Is it possible to observe the website functionalities and execute them directly from the console?

Question about JavaScript: Is it safe for a script tag to be visible in the body of the developer console and for functions to be run directly on the website? It raises security concerns, and there should be measures in place to prevent this kind of displa ...

What are the steps to integrate openjphjs with next.js?

I am working on a project with Next.js and need to utilize openjphjs for decoding HTJ2K pixel data. In order to incorporate openjphjs, I have included both openjphjs.js and openjphjs.wasm in a specific folder within the project structure. To address an e ...

Executing multiple server-side methods on an AJAX call in ASP.NET MVC: A comprehensive guide

I am facing a situation where I have a method that is called by jQuery, and its result is displayed on a popup. Sometimes, it takes some time to complete and a blank popup appears with processing message. When clicking on close, the popup disappears but th ...

disabling empty elements in a React JS JavaScript component

Currently, I am retrieving data from an API where users can post content up to 3 times. However, if a user has not posted three times, empty boxes with padding and background color will appear. I want to remove all elements that do not have any content wit ...

Tips for overriding ng-disable in AngularJSUnleashing the

This is a comment box using AngularJS: <tr> <td colspan="5"><br/>Comments* <div><textarea class="form-control" rows="3" cols="60" ng-model="final_data.drc_scope" placeholder="Add comments here" ng-disabled="is_team==0 || isDis ...

Is it possible to transfer files using web-bluetooth technology?

As I work on developing an embedded system that counts the number of cars, saves their speed and time data in a logs file using rsyslog. Simultaneously, I am creating a web-API (in Typescript/Angular with Electron for Desktop usage and later Web as well) t ...

Locating characters within a string using JavaScript

Currently, I am enrolled in JavaScript classes and have come across a challenging question. In this scenario, the task is to create a function named countLetters. This function will take two parameters: 1) sentence - this parameter should be of type stri ...

Encountered an issue with mapping data from a controller to a view in Angular.js

Currently, my application consists of only three small parts: a service that makes an http call to a .json file, a controller that receives data from the service and sends it to a view. Everything was working fine when I hard coded the data in my service. ...

Acquiring a property from an object that is specified within a function

I have created an object with properties inside a function: function createObject() { const obj = { property1: value, property2: value } } How can I access this object from outside the function? Would redefining it like ...

Utilize Vue's "v-if" directive to dynamically display or conceal steps according to the

Currently, both steps are hidden even though the step is 1. I must be doing something wrong here. When the step is one, it should display the form and when the step is 2, it should show the error message "Property or method 'step' is not defined ...