Transferring an array of props to a router-link destination

I'm currently working on dynamically updating a <router-link> path, depending on the view component it is being used in. Below you can see the <router-link> element that iterates through the compItems array, which is filled with data from each view component.

<router-link :to="{ name: compItem.name, params: { compItems: compItem.router } }" class="cz-ds-view-related-comp" v-for="compItem in compItems" :key="compItem.name">
  <div class="related-comp_icon"><img class="related-comp_icon" :src="require('@/assets/home/icons/' + compItem.atomicIcon + '')" alt=""></div>
  <div class="related-comp_title"><h3>{{ compItem.name }}</h3> <img src="../../assets/home/icons/arrow-right.svg"></div>
</router-link>
export default {
  name: 'relatedSection',
  props: {
      compItems: {
          type: Array
      }
  }
}
</script>

Here's an example of a view component setting up router data:

data () {
  return {
    compItems: [
      { name: 'Links', atomicIcon: 'atom.svg', router: 'links'}, 
      { name: 'Form Elements', atomicIcon: 'atom.svg', router: 'form-elements'},
      { name: 'Avatars', atomicIcon: 'atom.svg', router: 'avatars'},
      { name: 'Badges', atomicIcon: 'atom.svg',  router: 'badges'}
    ]
  }
}

Currently encountering a console error and seeking assistance.

Thank you in advance!


Edit:

Below is a snapshot from the router file:

const routes = [{
  path: '/',
  name: 'home',
  props: true,
  component: Home
}, {
  path: '/avatars',
  name: 'avatars',
  props: true,
  component: Avatars
}, {
  path: '/badges',
  name: 'badges',
  props: true,
  component: Badges
}, {
  path: '/buttons',
  name: 'buttons',
  props: true,
  component: Buttons
}, {
  path: '/breadcrumbs',
  name: 'breadcrumbs',
  props: true,
  component: Breadcrumbs
}, {
  path: '/form-elements',
  name: 'form-elements',
  props: true,
  component: FormElements
}, {
  path: '/icons',
  name: 'icons',
  props: true,
  component: Icons
},
 ...

Answer №1

The router's route definitions all specify lowercase name properties. When using a <router-link> to access them by name, it requires an exact match, but the compItems have names with capitalized letters.

In addition, you are incorporating route params in the link without any defined routes.

Here is a revised version of the code to enhance clarity and accuracy:

<template v-for="compItem in compItems">
  <router-link :to="{ name: compItem.name }" class="cz-ds-view-related-comp">
    <div class="related-comp_icon">
      <img class="related-comp_icon" :src="require('@/assets/home/icons/' + compItem.atomicIcon + '')" alt="">
    </div>
    <div class="related-comp_title">
      <h3>{{ compItem.title }}</h3>
      <img src="../../assets/home/icons/arrow-right.svg">
    </div>
  </router-link>
</template>
data () {
  return {
    compItems: [
      { title: 'Links', atomicIcon: 'atom.svg', name: 'links'}, 
      { title: 'Form Elements', atomicIcon: 'atom.svg', name: 'form-elements'},
      { title: 'Avatars', atomicIcon: 'atom.svg', name: 'avatars'},
      { title: 'Badges', atomicIcon: 'atom.svg',  name: 'badges'}
    ]
  }
}

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

Clicking on the Google Maps direction service can add additional markers to the map

If you can help me create a Google Maps direction service between two points or markers on a map click event, it would be greatly appreciated. I've set up a fiddle to demonstrate that when you click on the map for a second time, a third marker is dis ...

Bug causing connection issues in Node.js when dealing with IP redirection

I recently encountered an issue with NodeJS while using a kafka node on a node-red instance installed on my RPI3. Let me paint you the scenario: I have a cluster set up with a functioning Kafka instance. The machine hosting the Kafka broker has a private ...

Unable to retrieve information using an ajax get call

I have recently set up a MongoDB database with just one ID for testing purposes. I'm working on fetching data from the database using an Ajax GET request in my JavaScript file, which is built on the ImpactJS engine. Here is a glimpse of how my curren ...

What causes images to expand automatically when selected in my JavaScript gallery?

I am struggling with a simple JS gallery of images where I want to display a large image at the top and small thumbnails below it. The issue I am facing is that when I hover over an image in the thumbnail section, the big image changes as expected. However ...

Using JavaScript to convert an image URL to a File Object

Looking to obtain an image file from a URL entered into an input box, leading to the transformation of an image URL into a file object. To illustrate, when selecting a random image on Google Images, you can either copy the Image or its URL. In this scena ...

Creating objects in JavaScript using Object.create can sometimes cause issues in Internet

I have been working on software development for SharePoint 2013, specifically dealing with overriding SharePoint's file previewer (changing filepreview.debug.js to myfilepreview.debug.js). Unfortunately, we have encountered a problem with IE8, while e ...

Populating Redux form fields with data retrieved from API call

Currently, I am working on an address finder component in React and I am looking for the most effective way to update the fields with values once I receive the data from the API. I am using a fetch in React to fetch the data and fill in some form fields, t ...

Sending data from child components to parent components in Angular

I'm facing an issue with retrieving data from a child array named store within user data returned by an API. When trying to access this child array in my view, it keeps returning undefined. Code export class TokoPage implements OnInit { store= nu ...

Issues with validating and executing Javascript (HTML5 canvas)

Currently, I am tasked with creating a 3D application using HTML5 canvas for one of my courses. To achieve this, I decided to utilize Three.js. My initial goal is to render a simple plane and allow the camera to move along the x-axis when the mouse button ...

Ajax long-polling - Timeout triggering unexpectedly

I am having an issue with my Ajax code polling my IIS/ASP server. After calling msgPoll("") once, the function seems to be invoked repeatedly instead of every 30 seconds. Can you help me identify what mistake I might be making? var msgTimOut; f ...

Can someone help me figure out how to trigger my function after my jQuery 'each' function has completed along with all the AJAX calls it includes?

Hello all, seeking some guidance here. I have experimented with various solutions from SO and other sources. This particular one caught my attention as I tried to ensure that my function wouldn't execute until all ajax calls were completed. However, I ...

issue encountered when trying to deploy a React application on GitHub

I successfully created a todolist on localhost. Now, I am facing issues while deploying it on GitHub. When I run '$ npm run deploy' in the command prompt, I encounter errors. To troubleshoot, I have added 'homepage', 'predeploy&ap ...

Generate a fresh object with distinct identifiers

I am interested in creating a new object, utilizing unique keys consisting of comma-separated IDs. For instance, I have: const d = { "1,2,3,4,5,6,7,8,9,10": [ "created_by", "modified_on", "external_o ...

Compiling TypeScript on save disrupts AngularJS functionality in Visual Studio 2017

I am currently working on a project in Visual Studio Community 2017 (15.2) that involves AngularJS 1.6.5 and a NancyFX server. You can find the code for this project here: https://github.com/GusBeare/NancyAngularTests This project serves as a learning pl ...

Regular expression in JavaScript that can match two different potential combinations

To capture a specific combination of letters followed by a variable number in a string, stored in the input variable, I have set some rules. The letters must be strict while the numbers can vary. They can either be at the start of the string or immediately ...

Using JavaScript template literals to construct a query for a mongoose array

I'm currently working with mongodb and mongoose in conjunction with expressjs My database comprises the following array: _id:6262013fa90e7b533809140d isactive:true schedule:Array 0:Object 1:Object 2:Object 3:Object 4:Object 5:Object 6:Object name:&qu ...

Exploring the potential of Bootstrap/bootflat and jQuery progress bars

I am attempting to display and animate a progress bar while loading an HTML page into a div using jQuery. The progress bar I am using is from Bootstrap (Bootflat) and has the following structure: <div class="progress" style="visibility:hidden;"> ...

Exploring the power of asynchronous Mongoose queries using the async await

I have a system where authenticated users can create new user accounts and assign them to specific groups. The middleware flow for this process is outlined in the following route: router.post('/account/add-users', userController.validateRegist ...

Route fallback not yet resolved

Is it possible to set up a fallback route in angular routes? For instance, is there a way to specify a fallback route like this: $routeProvider .when('/a', { templateUrl: 'a.html', controller: 'aCtrl' ...

Maximizing the potential of asp.net and javascript when dealing with multiple fields and the onchange

My asp.net webpage is filled with numerous textboxes, each triggering a JavaScript function on the onchange event. The script changes a textbox to 'Y' to indicate which section of the page has been altered. While everything functions correctly, ...