Error Encountered in Vue.js when Trying to Access a Nested

Below is a snippet of my route code from app.js

let routes = [{
    path: "/dashboard",
    component: require("./components/Dashboard.vue")
  },
  {
    path: "/tour",
    component: require("./components/Index.vue"),
    children: [{
      name: 'create',
      path: '/create',
      component: require('./components/product/Create.vue')
    }]

  },
  {
    path: "*",
    component: require("./components/NotFound.vue")
  }
];

Master.blade.php

<div class="sidebar">
  <router-link class="btn btn-success" to="/dashboard">
    Dashboard
  </router-link>
  <router-link class="btn btn-success" to="/tour">
    Tour
  </router-link>
</div>
<div class="content">
  <router-view></router-view>
</div>

Index.vue

<template>
  <div class="container">
    <div class="row mt-5">
      <div class="col-md-12">
        <div class="card">
          <div class="card-header">
            <h3 class="card-title">Tours</h3>

            <div class="card-tools">
              <router-link class="btn btn-success" to="/tour/create">
                Add New
                <i class="fas fa-plus fa-fw"></i>
              </router-link>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body table-responsive p-0">
            <table class="table table-hover text-center">
              <tbody>
                <tr>
                  <th>ID</th>
                  <th>Name</th>
                  <th>Days</th>
                  <th>Price</th>
                  <th>Type</th>
                  <th>Image</th>
                  <th>Meta Title</th>
                  <th>Meta Description</th>
                  <th>Actions</th>
                </tr>

                <tr v-for="tour in tours.data" :key="tour.id">
                  <td>{{tour.id}}</td>
                  <td>{{tour.title}}</td>
                  <td>{{tour.days}}</td>
                  <td>{{tour.price}}</td>
                  <td>{{tour.category_id}}</td>
                  <td>
                    <i class="fas fa-check text-success" v-if="tour.image"></i>
                    <i class="fas fa-times text-danger" v-else></i>                      
                  </td>
                  <td>
                    <i class="fas fa-check text-success" v-if="tour.meta_title"></i>
                    <i class="fas fa-times text-danger" v-else></i>                      
                  </td>                  
                  <td>
                    <i class="fas fa-check text-success" v-if="tour.meta_description"></i>
                    <i class="fas fa-times text-danger" v-else></i>                      
                  </td>                  
                  <td>
                    <button @click="editModal(tour)" class="btn btn-primary btn-sm">Edit</button>

                    <button
                      @click="deleteUser(tour.id)"
                      class="btn btn-danger btn-sm"
                    >Delete</button>
                  </td>
                </tr>
              </tbody>
            </table>
          </div>
          <!-- /.card-body -->
          <div class="card-footer"></div>
        </div>
        <!-- /.card -->
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        tours: ""
      };
    },
    methods: {
      initialLoad() {
        axios.get("api/tour").then(({
          data
        }) => (this.tours = data));
      }
    },
    created() {
      this.initialLoad();
    }
  };
</script>

Index.vue displays all the saved tours from the database.

The Add New button within Index.vue loads the Create.vue component for creating tours. However, clicking on the create button leads to the NotFound.vue component from the wildcard route. No error messages are displayed either in the UI or console.

I've also tried:

import create from './components/product/Create.vue';

and replacing

require('./components/product/Create.vue')
with create

But no progress has been made. Can anyone identify what mistake I might be making here?

Answer №1

To begin, create a new file named Tourview.vue and save it inside the components folder.

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

<script>
  export default {
    data() {
      return {      
      };
    },
    methods: {

  };
  };
</script>

Next, update your routing file as shown below:

let routes = [{
    path: "/dashboard",
    component: require("./components/Dashboard.vue")
  },
  {
    path: "/tour",
    component: require("./components/Tourview.vue"),
    children: [
     {
      path:'',
      component: require("./components/Index.vue")
     },
    {
      name: 'create',
      path: '/create',
      component: require('./components/product/Create.vue')
    }]

  },
  {
    path: "*",
    component: require("./components/NotFound.vue")
  }
];

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

Is there a way to convert a json array to a javascript array in AngularJs?

I am new to Angular and front-end development and facing a challenge that I can't seem to overcome. After reassigning one variable to another: $scope.testarray = $scope.todos; only the 'todos' data is being displayed when using Angular bind ...

Tips for incorporating dynamic parameters/variables into templates displayed using ng-bind-html or a custom directive (within ng-repeat)

EDIT: I have created a solution sample based on the initial answer. However, I am open to further suggestions and would appreciate any help in filling the gaps in my knowledge (please refer to the comments). plnkr.co/edit/mqGCaBHptlbafR0Ue17j?p=preview OR ...

Error encountered in Bootstrap 5: Popper__namespace.createPopper function is not defined

Currently using Django to host web pages. Focus is on enabling offline access by downloading all necessary resources to ensure webpage functionality, like Bootstrap 5. Attempting to utilize the dropdown menu feature in Bootstrap: Dropdowns depend o ...

The requestify Node module encounters issues when the body contains special characters

My current project involves the use of node.js and a library called requestify. Here is the snippet of code causing some trouble: console.log('body'); console.log(body); return new Promise(function (f, r) { requestify.request(myurl, { ...

Using MySQL data in an EJS file to create a personalized Profile Page

In the midst of a personal project aimed at honing my web development skills and gaining a deeper understanding of the intricacies of the field, I have hit a roadblock. The focus of this project is to create a profile page, and while I have successfully co ...

How to Incorporate an Error Function into XPages Partial Refresh Events (dojo.xhrPost)?

I have a page that relies on multiple partial refreshes for user interaction. Rather than implementing a session keep alive mechanism, I am interested in detecting error responses from these partial refreshes to alert the user of their expired session or t ...

Everything was working perfectly with the Javascript code until I attempted to encapsulate it within

I found some helpful source code here for using AJAX to submit a form and store user information in a database using PHP. While the code I initially used worked, I realized that for efficiency, I needed to streamline it for multiple forms performing the sa ...

Module 'BrowserFetcher.js' could not be located

After updating all my npm packages, I encountered an issue when trying to run on my local server. The error message reads: Error: Cannot find module './BrowserFetcher.js' This error specifically points to a line in my puppeteer file located at - ...

Link that causes the regular expression test to hang

My goal is to create a regular expression that can accurately identify URLs. I found the code snippet for this on Check if a Javascript string is a url. The code looks like this: function ValidURL(str) { var pattern = new RegExp('^(https?:\/&b ...

The VueJS function is not defined

Looking for a way to fetch data from graphql in my vue project and store it in a variable. The function is asynchronous and the value of rawID needs to be awaited. However, there is a possibility that it could result in undefined, causing an error in the ...

To properly render an HTML file before loading a JavaScript file, express.static fails to serve the HTML file

Within my server.js file, the following code is present: var path = require('path'); var express = require('express'); var app = express(); var htmlRoutes = require('./app/routing/routes.js')(app, path, express); As for my r ...

The notification panel pop-up box keeps moving away from the right side

I'm currently in the process of creating a straightforward vertical notification panel, similar to the one seen on Stack Overflow. However, I've encountered an issue where the pop-up is not staying positioned correctly to the right side. It behav ...

Using an external script to modify or call a Vue.js method

My Vue app is constructed using Webpack and includes a few basic computed properties, such as calculating the sum amount from input values. However, I now require the capability to replace the summation function with one stored in a separate file that is n ...

Choose the right Vue.js component for optimal performance

I have a primary element within which there is a secondary element with vue.js 2.0. The issue arises when the secondary element relies on methods from the primary element. Here's an illustration: Vue.component('primary-element', { tem ...

Using Nest JS to create two instances of a single provider

While running a test suite, I noticed that there are two instances of the same provider alive - one for the implementation and another for the real implementation. I reached this conclusion because when I tried to replace a method with jest.fn call in my ...

Understanding the Importance and Benefits of Using the Classnames Utility in React Components

Can you break down for me the purpose of utilizing the Classnames utility in React code? I've reviewed the Classnames documentation, but I'm still struggling to comprehend why it is used in code like this: import classnames from 'classnames ...

Selecting a directive's scope

Though the title may not capture it quite accurately, I struggled to find a more fitting description. I crafted a directive that incorporates an ng-repeat: app.directive('appDirective', function($purr){ var template = '' + ...

The Node JS API remains unresponsive when the request parameters are increased, continuing to send multiple requests to the server without receiving

Using the API below returns nothing: http://localhost:6150/api/v1/simpleSurveyData/abc/:projectId/:startDate/:endDate/:visitMonth However, if I remove any of the four parameters or provide less than four parameters, and adjust the API route in Node.js acc ...

Encountering an issue when trying to submit a post request: "Received an API resolution without a response for /api/comments, which could lead to delayed requests."

Hey, I recently started diving into Next.js and I'm facing an issue with making a POST request to the API. In my project structure, I have a comments folder nested inside the api folder. Within the comments folder, I've written the following cod ...

Having trouble updating Vuejs array with new values

Currently, I am facing an issue with the template code for my survey builder. I am successfully receiving responses from the server, but the addAnotherQuestion value is not updating as expected. Despite trying various approaches, I have been unable to reso ...