The component fails to display on the page when using Vue-router

I'm having an issue with my router. I'm trying to display bodyComponent on my index page, but nothing is happening. I'm using laravel+vue. Can anyone point out where I might be going wrong?
Here's my router:

import Vue from 'vue'
import VueRouter from 'vue-router'
import bodyComponent from '../views/bodyComponent'

Vue.use(VueRouter)

const router= new VueRouter({
    mode: "history",
    routes:[
        {
            path:"/",
            components: {
                default: bodyComponent,
            }
        }
    ]
})
export default router;


My app.js file:

import router from "./router"
const app = new Vue({
    el: '#app',
    router
});


Here's my index.blade.php:

<div id="app">
        <header-component></header-component> 
        <!--<body-component></body-component>-->
        <router-view></router-view>
        <footer-component></footer-component>
</div>

Answer №1

After updating the path in my Vue router, the components are now displaying on the index page. The index page is accessed through the Laravel router, so I made sure to change the path in the Vue router to match the name defined in the Laravel route.
Here is my Laravel route:

Route::get('/tobyten', function () {
        return view('tobyten.index');
    })->name('tobyten');


And here is my Vue router configuration:

const router= new VueRouter({
    mode: "history",
    routes:[
        {
            path:"/tobyten",
            components: {
                default: bodyComponent,
            }
        }
    ]
})

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

Enhance your browsing experience with a JavaScript bookmarklet that allows you to easily search through

Struggling to develop a JS Bookmarklet that scans the source code of the current page for a specific code like "G1_Value_client." If found, I need it to trigger alert A; if not found, trigger alert B. Seeking assistance as I am facing some challenges with ...

Modify the CSS style of the select label and change the color of the currently selected option in MUI

For the past few days, I've been facing challenges with implementing MUI components while working on a page for a React app. I'm almost finished with my project, but there are 2 key things missing... On my page, I have utilized a Select and an ...

Creating a customized bundle with Bootstrap using the Rollup tool

In the official Bootstrap 5 documentation, it mentions that we can import pre-compiled js files from bootstrap/js/dist and create a custom bundle using tools like Webpack or rollup. https://getbootstrap.com/docs/5.0/getting-started/javascript/#individual- ...

Exploring the process of setting up Jasmine tests for both services and controllers in Angular.js

I have been facing challenges in creating accurate tests for my Angular services and controllers, even though they are functioning correctly. I have searched extensively for a solution to this problem. Below is an example of my controller: angular.module ...

Utilizing MongoDB for Storing Session Information

When working with Laravel and MongoDB as the database, I encountered an issue where session data was not being saved correctly. Initially, everything worked fine with the file session driver, but when switched to the database driver, it started creating ne ...

Characteristics of events within the embed element

<div id='aplayer'></div> js $('#note').click(function() { $('#aplayer').html("<embed src=" + music + " onended='test();'" + ">"); }); function test(){ alert ('525'); } audio is ...

Adjusting the transparency of numerous elements using JavaScript or jQuery

My task involves creating a large form where elements initially have an opacity of 0.5, and when a button is clicked, the opacity changes to 1.0. While I can achieve this using JavaScript, I want to find a more efficient way by avoiding individual if state ...

Changes to the className of a React component will trigger a re-render of

When the className of the parent changes, React children will re-render. import React from 'react'; import { useSelector } from 'react-redux'; import items from './ItemsList.js'; import Item from './Item'; import &ap ...

Clicking the submit button in JavaScript will trigger a request to the Spring MVC backend,

When I use the following code, it gives me an object response: @RequestMapping(value = "/NewLogin",method = RequestMethod.POST) public @ResponseBody Token getAllBooks( Token token = new Token(); token.setValue(encryptedMessage); return toke ...

What is the process for issuing https requests with SuperAgent?

In my React Native Android project, I am utilizing SuperAgent, which works similarly to Node.js. My goal is to make an API call using the https protocol. However, when I simply use the following code: Req = SuperAgent .get(‘https://url...') ...

Retrieving the value of a specific image using Jquery

<div id="choose"> <div class="picked"> <img src="/def/image1.png"> </div> <div> <img src="/def/image2.png"> </div> <div > <img src="/def/image3.png"> </div> </div& ...

passing a PHP variable into an HTML input field

Recently, I've encountered a problem where I need to transfer PHP variables to HTML input fields. echo $ManuellTagnavnMain; for ($n = 0; $n < 6; $n++) { print_r(++$ManuellTagnavnMain.PHP_EOL); } I'm looking for a way to pass these values ...

Having trouble with mdi-icons not displaying in your Laravel 8 project using Vue 2 and Vuetify?

I've been struggling to get the material design icons to load in Vuetify while using it with Laravel 8. I've attempted adding them via NPM following the instructions in this post, and I've also tried loading them via CDN using sass as demons ...

Utilizing Zustand state management with Next.js 13.4.12 for routing and server-side rendering, enhanced with local storage

My Zustand store code looks like this: import create from "zustand"; import { persist } from "zustand/middleware"; const useProjectStore = create( persist( (set) => ({ selectedProject: null, setSelectedProject: (pr ...

Two separate occurrences hold identical values

I'm encountering an issue where instantiating a class two times results in the second instance retaining parameters from the first instance. Here's a simple example: var Test = function() {}; Test.prototype = { bonjour: null, hello: { h ...

HighStocks should show categories instead of dates

The zoom function in HighCharts is what drew me to it initially. Everything was working perfectly until I encountered an issue that I can't seem to resolve. Here's my code snippet: http://jsfiddle.net/ma50685a/16/ $(function() { // Crea ...

Update the PHP webpage dynamically by utilizing AJAX and displaying the PHP variable

I am working on a PHP page that includes multiple queries, and I would like to be able to include this page in my index.php file and display the results with an automatic refresh similar to the Stack Overflow inbox feature. Is there a way to achieve this ...

Ensure that input field is validated only upon clicking the save button in Angular framework

Can anyone suggest the most efficient method to validate required fields in an input form using AngularJS? I want to display an error message only after the user clicks the save button (submit). Thank you in advance. ...

Tips for converting PDF files to images or reducing PDF file size using JavaScript

In my web application built with Next.js, I have a requirement where users can upload PDF files. However, I need to compress these files to a smaller size (e.g. 1MB). Despite searching extensively, I haven't found a satisfactory solution that meets my ...

What is the recommended location for storing an array of configuration values in Laravel 5?

Here is a list of Google Font settings that I have in an array: $googleFontList = array( 'Abril Fatface' => array( 'link_code' => 'Abril+Fatface', 'css_name' => 'Abril Fatface' ...