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

Triggering jQuery accordion when clicked

I have a challenge to tackle - I want to create an accordion system that can display and hide quotes at various points on the page. My desired outcome is to have one quote displayed per accordion panel. When I expand an accordion, I want to show the cont ...

The function document.getElementById is unable to select multiple elements simultaneously

I've been tackling a loading issue. I have a visible div, #loading, and multiple hidden divs, #message. I also have a JavaScript function. function loading() { setTimeout(function() { document.getElementById("loading").style.display = " ...

The jQuery .val() function does not function properly when using 'this'

This is an example with a textarea: <textarea id='ta' onkeydown='down(this)'></textarea> and here is the accompanying JavaScript code: <script> function down(input) { alert(input.val()); // not functioning ...

What is the process of transforming an object type into a two-dimensional array using lodash?

In order to properly display multiple tables in my Angular project, I am looking to convert an object type into an array of different objects. The object I am working with is as follows: let myObject = { internalValue:{city:"Paris", country:"France", pin ...

Change the font awesome class when the button is clicked

Here is the code I have in this jsfiddle. I am trying to change the font awesome icon on button click using javascript, but it doesn't seem to be working. I am new to javascript, so please pardon me if this is a silly question. HTML <button id="f ...

Encountering a Vue npm installation issue

When following a tutorial, version information can be crucial. [root@localhost my-project]# node -v v6.11.3 [root@localhost my-project]# npm -v 3.10.10 [root@localhost my-project]# vue --version 2.9.2 [root@localhost my-project]# cat /etc/redhat-releas ...

Generate a fresh object if the values within the TypeScript object are identical

How can I filter an object to return a new object containing elements with the same values? For example: allValues = {"id1": 3, "id2": 4, "id3": 3} The desired output is: filteredValues = {"id1": 3, "id3": 3} This is because the keys "id1" and "id3" hav ...

What could be causing the href to malfunction on my local website?

I'm currently working on adding a new link that directs to a local HTML website within a menu list on a website. The main website is in ASPX format, but my focus is on the HTML version. The link I want to add leads to an HTML website stored on my loca ...

Determine whether the request was made using ajax or traditional non-ajax methods

While testing the PHP code below, I noticed that the headers in the request do not indicate that it is JavaScript sending the request instead of a non-JavaScript user: Accept:*/* Accept-Encoding:gzip,deflate,sdch Accept-Language:en-US,en;q=0.8 AlexaToolba ...

Halting Execution After Placing an Object in Three.js Scene with Javascript

It seems like a simple task, but I've been struggling with it for days. How can I add objects to a scene with a pause between each addition? Inside a loop{ I call the make_obj function() then I call the wait function() } The issue is that the pr ...

The architecture of Angular controllers

Being a novice in AngularJs, I have a query regarding the controller structure. This particular file is my employeeController.js (function() { angular.module('employeeApp').controller('employeeController', employeeCont ...

In order to display the new component upon the first click in React, my button requires a double click

I have a project that utilizes the open Trivia API to fetch data. I've completed the development and everything appears to be working well so far. However, there's a bug where upon initially rendering the app, the first time I click the button to ...

Tips for setting cookie options in cookie-session version 1.0.2

Currently, I am delving into the intricacies of the "cookie-session" module in Node.js. https://github.com/expressjs/cookie-session My struggle lies in comprehending how to pass options for the cookie, particularly regarding expiration time. The default ...

Issues with JavaScript causing YouTube embed player to malfunction

For the past few days, I've encountered an issue where my JavaScript code to embed YouTube videos isn't working properly. The video loads but it's not playable as the play button is unresponsive. The console shows this error: Uncaught TypeE ...

Securing pathways and pages using NextJs

I recently completed a project where I implemented route protection for a website using the if and else statements, assigning each page a function withAuth(). However, I have concerns about whether this is the most effective method for securing routes in n ...

Sending JSON data back to the server using KeyValuePair in C#

My goal is to send my JSON list back to the POST method (EditCompanyReportField) on the C# server side. The related parameter (fieldSorted) in my method is an array object, but the values are not being passed through. I have a few question marks regarding ...

Eliminating pins from Biostall Google Maps plugin in CodeIgniter

After successfully setting up the Biostall Google Maps for Codeigniter, I am now looking to remove specific markers using ajax. The JavaScript code being executed is as follows: var myLatlng = new google.maps.LatLng(53.236114, 6.496444); var markerOption ...

What is the best way to determine the width of a CSS-styled div element?

Is there a way to retrieve the width of a div element that is specified by the developer? For example, using $('body').width() in jQuery will provide the width in pixels, even if it was not explicitly set. I specifically need to access the width ...

What is the best way to implement automatic scrolling to the bottom of a materialUI drawer in React after a page refresh?

I am facing an issue with my Material UI Drawer, which contains numerous checkboxes and radio buttons for an advanced search page. Whenever a checkbox or radio button is clicked, it triggers an API request to fetch results instantly without requiring a sub ...

"multer's single file upload functionality is not functioning properly, but the array upload

Currently, I am facing an issue while using react js to upload a single file. Interestingly, the multer.single() method seems to fail, whereas the multer.array() method works perfectly fine. What could be causing this problem? //Node.js const upload = mult ...