Oops! Vue.js router configuration is throwing an error because it's unable to read properties of undefined when trying to access 'use'

Description: I have been working on a leaderboard web application using Vue.js. When I tried to launch the server on localhost after finishing my code, I encountered an error. The error message I received is as follows:

Uncaught runtime errors:

ERROR
Cannot read properties of undefined (reading 'use')
TypeError: Cannot read properties of undefined (reading 'use')
    at eval (webpack-internal:///./src/router.js:10:45)
    at ./src/router.js (http://localhost:8080/js/app.js:79:1)
    at __webpack_require__ (http://localhost:8080/js/app.js:203:33)
    at fn (http://localhost:8080/js/app.js:436:21)
    at eval (webpack-internal:///./src/main.js:4:65)
    at ./src/main.js (http://localhost:8080/js/app.js:69:1)
    at __webpack_require__ (http://localhost:8080/js/app.js:203:33)
    at http://localhost:8080/js/app.js:1324:109
    at __webpack_require__.O (http://localhost:8080/js/app.js:249:23)
    at http://localhost:8080/js/app.js:1325:53

I attempted creating a new project to troubleshoot the error, but unfortunately, the problem persists. Even after reinstalling both Vue and Vue Router multiple times, the issue remains unresolved. I am reaching out for assistance in identifying and resolving the underlying problem.

import Vue from "vue";
import VueRouter from "vue-router";

import Scoreboard from "./components/ScoreboardTable.vue";
import Submissions from "./components/SubmissionDetails.vue";

Vue.use(VueRouter);

const routes = [
  { path: "/scoreboard", component: Scoreboard },
  { path: "/submissions/:problemId", component: Submissions },
];

const router = new VueRouter({
  routes,
});

export default router;

The main goal of this project is to create a single-page app that displays a competition's scoreboard. The app should consist of two pages - the Scoreboard page and the Submissions page, each serving its own specific purpose.

Your help in pinpointing and rectifying this issue is greatly appreciated. Thank you in advance!

Answer №1

When working with Vue 3, it is important to note that you should create the router using createRouter() instead of instantiating vue-router as you would have done in Vue 2 (Vue.use(...)).

To implement this in Vue 3, you can follow these steps:

import { createRouter, createWebHashHistory } from 'vue-router'

const routes = [...]

const router = createRouter({
  history: createWebHashHistory(),
  routes,
})

const app = Vue.createApp({})
app.use(router)

For more information, refer to the official documentation.

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

Maximize the sum of diverse numbers effectively

I have an array that contains objects structured like this: [ { "id": 91, "factor": 2, "title": "Test Product", "price": 50, "interval": 1, "setup": 0, "optional": false }, { "id": 92, "factor": 1, "title": "A ...

Vue chart not displaying data until the window is resized

I've encountered an issue with my apexchart where the data is not displayed when the page loads. It only appears when I zoom in/out or resize the window, which seems odd to me. I came across a similar problem on the apexcharts github, but it doesn&apo ...

Enhancing user experience by implementing AJAX in a contact form to eliminate the need for page

I have read numerous questions on this topic and have compiled the code I currently have from various responses. Unfortunately, despite my efforts, I am unable to make it work and I cannot identify the reason behind this issue. Below is the HTML form str ...

What is the best way to conceal the outline in a popup window?

I have successfully implemented a popup/modal window using JavaScript, but now I need to find a way to hide the outline map container. The initialization code for the map is as follows: self.mapDialogOptions = { autoOpen: false, m ...

Is there a way to confirm that a file has been chosen for uploading prior to form submission, by utilizing the jquery validator?

I have a section on my website where users can upload files. I am trying to implement validation to ensure that a file has been selected before the form is submitted. Currently, I am using the jQuery form validator plugin for handling form validations. Th ...

Utilize a function to send an AJAX email

In my JavaScript function, I have been attempting to send an email from a contact form. The validation checks are working correctly, but when the code reaches the point of sending the form, it gets stuck and doesn't receive any response from $.ajax. I ...

Removing an item from a table row cannot be completed due to the inability to retrieve the list_body ID necessary for deletion

I have been working on enhancing the delete button function in my table. The id linked to the list_body must be incorporated into the delete function code. I utilized some jquery methods to render the list onto the webpage. //retrieve user list information ...

What are the solutions for fixing the issue of infinite redirection error in Vue Router?

I encountered an issue while trying to implement a check in router.beforeEach where I wanted to verify if there is a sessionToken stored and redirect to the Login page if it's not available: There seems to be an infinite redirection happening in a nav ...

Unexpected Undefined Return in Request Parameters

Hey everyone, I'm currently working on setting up a mock API server using a JSON file with some dummy data. The first route I created is functioning perfectly: const express = require("express"); const router = express.Router(); const data = requir ...

Stencil - React Integration Does Not Support Global CSS Styling

As per the guidance provided in the Stencil docshere, I have established some global CSS variables within src/global/variables.css. This file is currently the sole CSS resource in this particular directory. Upon attempting to incorporate my components int ...

When attempting to render 2 components based on the results of 2 fetch calls using Promise.allSettled(), I encounter difficulties if one of them throws an error

I have encountered an issue while using Promise.allSettled() in sending two fetch calls. I am rendering components based on the result - a component with data if it is fulfilled and an error component if rejected. However, when one of the fetch calls throw ...

Is Protractor compatible with Internet Explorer 9?

For my Angular App that is running on IE9, I need to create end-to-end acceptance tests. I'm curious to know if the browser simulated by Protractor matches the behavior of IE9 or a newer version? ...

Is there a versatile Node.js HTTP request module that is compatible with both server-side and browser-side development, particularly when packaged with Webpack?

Currently, I am searching for a request module that can operate seamlessly in both the Node.js server and the client when compiled with Webpack. The requirements are quite straightforward. I simply need to execute some basic HTTP Ajax requests such as get ...

Combining two elements in Angular 2

I am looking to find the intersection of two objects. My goal is to compare these objects and if they have matching values on corresponding keys, then I want to add them to a new object. obj1 = { "Projects": [ "test" ], "Companies": [ "facebook", "google ...

The $scope.$watch function is not triggering events within a controller of a ui.bootstrap.modal

Currently, I am utilizing UI bootstrap for Angular and have successfully integrated the ui.bootstrap.modal component into my project. Everything seems to be working smoothly except for one issue I am encountering. Despite setting up a $scope.$watch to trac ...

How can I simulate a side plugin for Vue component testing?

I am currently using Vue 2 along with vue-test-utils and jest for testing. One of the plugins I use is vue-croppa, which allows me to upload pictures. import Croppa from 'vue-croppa' Vue.use(Croppa, { componentName: 'image-croppa' }) ...

Pass user input values to PHP via AJAX and display the outcome on a designated div

I am currently working on a project where I need to send an input value to a PHP script and display the returned value in a div using AJAX. However, I seem to be struggling with getting it to work properly. Any assistance or suggestions would be greatly ap ...

The PHP application encountered an error when trying to use an object of the mysqli_result type as an array

In my section, I have a straightforward display of data sourced from the database. Upon clicking options like construction and selecting countries like Algeria, the displayed values are [251, 211,712]. Similarly, for selections like Power in Egypt, the ou ...

Controlling the window opener; Inserting text into an element in the parent window

A pop-up window allows users to select files, then displays the selected image's URL. However, I need to take additional steps beyond that. I am seeking a method to input the URL into an input element on the parent window. window.opener.document.wri ...

I am unable to achieve negative X degree rotation of the image while using mousemove to rotate it

I need assistance with moving a picture in 3D. I want the offsetX of the mouse to be positive when it's past half of the picture, and negative otherwise. How can I achieve this effect for rotation degrees? This is what I have tried: $('#img ...