Having trouble importing components within my router.js file in VueJS

Trying to work with the vue-router, but encountering difficulty importing components into the router.js.

Received a warning:

[Vue Router warn]: No match found for location with path "/"

In need of assistance as I'm unsure of what mistake I might be making.

MAIN.JS

import { createApp } from 'vue';
import App from './App.vue';
import router from './router/router.js';

import '@popperjs/core'
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap-icons/font/bootstrap-icons.css'
import store from './store/store.ts'

createApp(App).use(store).use(router).mount('#app')

ROUTER.JS

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

//Attempts made to import components
//import test from "../components/test.vue";
//const test= () => import("../components/test.vue");

export default createRouter({
    history: createWebHistory(process.env.BASE_URL),
    routes: [
      {
        path: "/test",
        name: "TEST",
        component: () => import("../components/test.vue")
      }
    ]
  });

MY STRUCTURE

- src
    - assets
    - store
    - components
        - test.vue
    - router
        - router.js
    - App.vue
    - main.js

Desired outcome is to open the component in a new window using this code:

methods: {
  after_button_click() {
    let route = this.$router.resolve({ name: "TEST" });
    window.open(route.href, "_blank");
  },
}

INFO: No error messages received but functionality not working properly.

Answer №1

In my own application, I have a setup that is quite similar and it functions perfectly:

main.js

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'

index.js (found within './router'

import { createRouter, createWebHistory } from 'vue-router'
import TestComponent from '../components/TestComponent.vue'

const routes = [
  {
    path: '/test',
    name: 'test',
    component: TestComponent

  }]
const router = createRouter({
  history: createWebHistory("/"),
  routes
})

export default router

By following these steps, you should have a functioning router when you navigate to /test.

I hope this explanation proves helpful!

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

Error message: "PHP encounters an issue with jQuery due to absence of 'Access-Control-Allow-Origin' header"

I am currently attempting to make an external API call in PHP using AJAX and jQuery, but I keep encountering the error message saying "No 'Access-Control-Allow-Origin' header is present". The API does not support JSONP. Is there any workaround t ...

Incorporating PruneCluster into an AngularJS Leaflet Directive for Enhanced Mapping

I am currently facing an issue with loading clustered markers for geojson data using PruneCluster. The clusters are not appearing on the map and there are no errors showing up in the console to assist with troubleshooting. Below is the snippet of my curr ...

Node.js equivalent of Java's byteArray

I have a Node.js REST API with images being sent from a Java application as byte arrays. Here is an image Below is the string representation of the image in byte array form: [B@c75af72 I need to decode this byte array to verify if it is indeed an ima ...

Get a Blob as a PNG File

Hope you had a wonderful Christmas holiday! Just to clarify, I am new to JS and may make some unconventional attempts in trying to download my Blob in PNG format. I am facing an issue with exporting all the visual content of a DIV in either PDF or image ...

What is preventing the addition of links to the navigation bar when using a sticky navigation bar?

Currently, I am in the process of developing a blog website using Django. One of the features I have successfully implemented is a sticky navigation bar. However, I am facing a challenge with adding links to the menu on the navigation bar due to existing ...

Exploring the method of displaying a JSON 2D array through the utilization of getJSON

Is there a way to read 2D JSON data? An example of a JSON file is given below: [ { "name":"Menu1", "permission":"1", "link":"http://naver.com" }, { "name":"Menu2", "permission":"2", "link":"http://daum.net", ...

Tips for showcasing the Phaser game screen exclusively within a React route

I am trying to make sure that my game screen only appears on the '/game' route. However, when I initialize it using the method "new Phaser.Game(config)", it ends up displaying on every route including '/home', the default route '/& ...

Utilizing $store in field callback with VueJS and vue-form-generator

I've been utilizing the vue-form-generator component to work on my project. My goal is to update a variable in the store using the response from a callback function. Below is what I think is the relevant code (found inside the schema:fields property): ...

Please explain the concept of the Node.js event loop

I've spent countless hours poring over guides and resources on the event loop, yet I still can't grasp its essence. It's common knowledge that the libuv library is responsible for implementing the event loop, but what exactly is this entity ...

A error was encountered stating that the formValidation function is not defined when the HTML form element is submitted

Having trouble calling a function and receiving an error message. How can I resolve this issue? The error message reads: index.html?email=&gebruikersnaam=&wachtwoord=&submit=Submit:1 Uncaught ReferenceError: formValidation is not defined at HT ...

The function $(this).addClass() seems to be malfunctioning

While trying to follow a tutorial, I noticed that the style sheet isn't being applied to the clicked element in the list. What could be causing this issue? In the example provided, when a string is added to the text box and the button is clicked, a n ...

What is the reason for needing to export the function when importing a module in an Angular appModule?

I came across the following code snippet @NgModule({ declarations: [ ... ], imports: [ RoutingModule, SharedModule, JwtModule.forRoot({ config: { headerName: 'Authorization', tokenGetter: () => lo ...

React is choosing to re-render only one of the setState functions, neglecting the other

I'm currently in the process of developing a basic Tic Tac Toe game using React. The Objective: Each button in the game has its own state. When a button is clicked, it should change from ' ' to an 'X' and update the player's ...

Tips for transferring canvas information from JavaScript to Django using Ajax

Currently, I'm developing a Django application that allows users to activate their webcams and capture photos. These images are stored in a canvas, and my goal is to send this image to Django views so that it can be saved on the server. To trigger th ...

Having issues with the functionality of Bootstrap 4 popover?

In my Spring MVC web project, a Bootstrap popover appears when the help icon is clicked. However, on the first click, the popover opens and moves away from the icon. After closing it and clicking again, the popover correctly positions itself. When I chan ...

What is the best approach to building this using Angular?

Greetings, this marks the beginning of my inquiry and I must admit that articulating it correctly might be a challenge. Nevertheless, here's my attempt: Within the following code snippet, there lies an element that effectively fills up my designated ...

What could be the reason for a code running successfully in node but not in the REPL environment?

This is the current script I'm working with: const lib = require('./lib.js'); const fs = require('fs'); const graph = fs.readFileSync('../js-working-dir/add_graph.pb', 'utf8'); const sess = new lib.Session(gr ...

Steps to create a function in a .js file that uses ng-show conditions

I am in the process of validating a web page where the user inputs must be alphanumeric, have a maximum length of 45 characters, and be unique. Below is the code snippet I am working with. Is there a way to consolidate these three ng-show conditions into ...

Validation of date type input using Vee-Validate and Bootstrap-vue

I'm attempting to utilize vee-validate to verify if the user is inputting a valid date in a bootstrap-vue date input field. Even after following the vee-validate documentation, it appears that the expected behavior is not being achieved. Validation d ...

Toggle menu visibility when body is clicked

<script> $(".bg").on('click', function(e) { e.preventDefault(); $("#navMenu").removeClass('open'); $("#searchBar").removeClass('active'); }); </script> My goal is to togg ...