Unable to access path for children through buttons in parent path

As a data scientist entering the world of frontend development, I find myself faced with the task of creating a UI at the request of my boss. Please bear with me as I attempt to explain my issue in layman's terms.

Currently, I am using Vue.js and have a parent component called home/settings which contains a menu leading to various sub-pages. The problem arises when clicking on the menu item for page1 under home/settings, it redirects to home/page1 instead.

If I manually input

home/settings/page1</code, the navigation to other sub-pages works fine. However, when starting from <code>home/settings
, the system mistakenly replaces settings with page, resulting in a dead end.

The configuration in the router.js file is structured as follows:

Vue.use(Router)
export default new Router({
  routes: [
    {
      path: '/',
      components: { base: Home },
    },
    {
      path: '/Settings',
      components: { base: Settings },
      children: [
        {
          path: '/',
          components: { settingsMain: SettingsPage1 },
        },
        {
          path: 'page1',
          components: { settingsMain: SettingsPage1 },
        },
        {
          path: 'page2',
          components: { settingsMain: SettingsPage2 },
        },
      ],
    },
  ],
})

The component within Settings can be visualized as:

<template>
  <fd-menu @select="goToPage">
    <fd-menu-list>
      <fd-menu-item value="1">
        Setting 1
      </fd-menu-item>
      <fd-menu-item value="2">
        Setting 2
      </fd-menu-item>
    </fd-menu-list>
  </fd-menu>
</template>

<script>
export default {
  methods: {
    goToPage(item)
    {
      this.$router.push('page' + item.value)
    }
  }
};
</script>

Additional information can be provided upon request. Thank you!

Answer №1

When using router.push, it is important to ensure that the full navigation path matches routes similar to <router-link>. Make sure to set the complete child path for accuracy.

For example, use

this.$router.push('/settings/page' + item.value)
to properly navigate to the desired page.

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

The Vue.JS application encountered an error while making an API request, resulting in an uncaught TypeError: Cannot read properties of undefined related to the 'quote'

<template> <article class="message is-warning"> <div class="message-header"> <span>Code Examples</span> </div> <div class="message-body"> ...

Expanding upon passing arguments in JavaScript

function NewModel(client, collection) { this.client = client; this.collection = collection; }; NewModel.prototype = { constructor: NewModel, connectClient: function(callback) { this.client.open(callback); }, getSpecificCollection: ...

Using references to pass variables in TypeScript [Angular 8]

I have several variables within the html of this component that are assigned their values by the typescript file. The declaration in the html is as follows: <h1>{{myproperty1}}<\h1> <h1>{{myproperty2}}<\h1> <h1>{{myp ...

Utilizing AJAX in Tables: Implementing an Onclick Function in a Button within a Table to Access JSON Data

I am trying to trigger a function by clicking on a button and passing the position's ID as a parameter, but I am facing some difficulties in understanding how to achieve this with the given syntax. Can anyone guide me through this process? functi ...

Hey there! Can anyone assist me in figuring out how to configure vue swiper to function exclusively on mobile screens?

Is there a way to make the vue slider (swiper) only work on mobile screens and disable it on computer screens? I would greatly appreciate any help or advice on how to achieve this. Below is the Vue code that I am currently using: <template> <s ...

The issue of Next.JS fetch not caching data within the same request

I am faced with a straightforward setup where a Next.JS server-side component is responsible for fetching and displaying a post. The challenge lies in setting the page title to reflect the title of the post, requiring me to call my posts API endpoint twice ...

Guide on how to showcase JSON data using vanilla JavaScript within the Laravel framework

As a beginner in Laravel, I am looking to pass JSON data from my controller using vanilla JavaScript to my view blade. However, I am unsure of the steps to accomplish this. Below is an example of my controller: public function index(Request $request) { ...

Anguar server encountered a startup issue and failed to initialize

My server.js file looks like this: var express = require('express'), api = require('./api'), app = express(); app .use(express.static('./public')) .use('./api', api) .get('*', ...

Having trouble loading the Google API using getScript. Is displaying a ReferenceError message: "Variable google not found."

I am attempting to dynamically load the Google API using the getScript() method for implementing a "Place Autocomplete Address Form". For more information, you can visit this link: https://developers.google.com/maps/documentation/javascript/examples/places ...

React Navigation ran into an issue with the specified location

It seems that I am encountering an issue where it is displaying a message stating "no routes matched for location '/'". However, the Header file clearly shows that there is a home component defined for this URL. For further clarification, you ca ...

Having an issue with the pop state function not functioning correctly

I am facing an issue with my images where clicking on a specific image changes the URL to that ID. However, I can only go back once and then the same URL is repeated every time I press the back button. Additionally, the forward button does not work at all. ...

There was a failure to establish a Redis connection to the server with the address 127.0.0.1 on port 6379

Currently, I am working with node.js using expressjs. My goal is to store an account in the session. To test this out, I decided to experiment with sessions by following the code provided on expressjs var RedisStore = require('connect-redis')(ex ...

triggering the onsen's setMainPage function when clicked using a variable from ng-repeat loop

I need help customizing my Onsen UI splitView app to dynamically set the main page based on a variable received from a clicked item in a list generated by ng-repeat. After researching ng-repeat and ng-click, I am still unable to achieve the desired outcom ...

Utilizing the power of Material-UI with React in conjunction with Python-Django: A comprehensive

I am seeking guidance on implementing React with Material UI components in my web application. The technologies I have utilized in multiple projects include: Materialize CSS, Javascript, Jquery. The technologies I wish to explore for future projects are ...

Can JavaScript be used to dynamically assign events to elements on a webpage?

I am currently using the following code: if ( $.support.touch == true ) { $(window).on('orientationchange', function(event){ if ( full == false ) { self.hideAllPanels("7"); } }); } else { $(window).on(&apo ...

Error message: Unable to access properties of undefined object (reading 'authorization')

This is a snippet of code that handles user authentication and authorization const bcrypt = require("bcryptjs"); const jwt = require("jsonwebtoken"); const userRepository = require("../repositories/userRepository"); const SALT ...

Updating Rails Partial with JSON Data

Updating a partial by appending fetched Facebook posts using the koala gem requires some code adjustments. Here is an example of how to achieve this: # feed_controller.rb def index end def fb_feed @fb_feed = .. respond_to do |format| format.js { ...

Implementing a jQuery change event to filter a specific table is resulting in filtering every table displayed on the page

I have implemented a change event to filter a table on my webpage, but I am noticing that it is affecting every table on the page instead of just the intended one. Below is the code snippet: <script> $('#inputFilter').change(function() { ...

Encountering a 403 error while attempting to install Meteor with npm using the command npm install -

Following the installation instructions provided on the official Meteor website at , I encountered an error while trying to install Meteor using the command "npm install -g meteor". Here is the detailed error message: os  win 10 pro node -v  v14.15.1 n ...

What is the correct way to implement fetch in a React/Redux/TS application?

Currently, I am developing an application using React, Redux, and TypeScript. I have encountered an issue with Promises and TypeScript. Can you assist me in type-defining functions/Promises? An API call returns a list of post IDs like [1, 2, ..., 1000]. I ...