Struggling to navigate to another page using Vue Router?

I'm currently in the process of integrating Vue Router into one of my projects to enable navigation between different pages.

Since I'm not very familiar with Vue Router, there's a chance I may have made a mistake in the setup.

import {createRouter, createWebHistory} from 'vue-router'
import App from '../App'
import Test from '../Views/Test'


const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path:'',
            name: 'App',
            component: App,
        },
        {
            path:'/test',
            name: 'Test',
            component: Test
        }
    ]
})
export default router

This is the content of my index.js file. The issue I'm facing is that when I run my code, I can view the App page without any problems. However, if I manually access http://localhost:8080/test, I encounter an error stating that the page could not be found.

Could someone assist me with this problem?

Thank you!


UPDATE

I made some changes and now I'm able to access my pages, but only through a router-link. I have included a First.vue page where I can decide to navigate to either App.vue or Test.vue.

My First.vue:

<template>
    <router-view></router-view>
    
    <router-link to='/app'>Go to application</router-link>
    <br>
    <router-link to='/test'>Go to test</router-link>
    
</template>

and my `index.js` has been updated to:

import {createRouter, createWebHistory} from 'vue-router'
import App from '../App.vue'
import Test from '../Views/Test.vue'
import First from '../Views/First.vue'


const router = createRouter({
    history: createWebHistory(),
    routes: [
        {
            path:'/',
            name: 'First',
            component: First,
        },
        {
            path:'/test',
            name: 'Test',
            component: Test
        },
        {
            path:'/app',
            name: 'App',
            component: App
        }
    ]
})
export default router

Answer №1

Upon careful examination of your sandbox, it appears that the issue lies within your export and import statements, as they are mismatched.

If you export your module in the following way:

export const controller = createController({
  ...
});

then the corresponding import statement should be:

import { controller } from "./controller/index";

However, if you export your module like this:

const controller = createController({
  ...
});
export default controller;

then the import statement should be:

import controller from "./controller/index";

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

Retrieve the Date information and transfer it to another page using a combination of jQuery, JavaScript, and PHP

I feel defeated trying to solve this problem. Can anyone offer assistance in figuring this out? I've spent an entire day debugging with no success. I have two PHP files, index.php and home.php. In the index.php file, I include the Date range picker, ...

Using Jquery to manipulate arrays based on options selected from a dropdown menu

I am currently working on a feature that suggests tags based on the selected category. This involves using a select box to choose a category and then displaying sub-categories in a list. Here is the current setup: <select id="categorySelect"> < ...

Swap out the CSS line for a PHP conditional statement

My goal is to change a CSS line when a specific condition is met. When I click on the Ok button, a lot of data is displayed. Depending on the selection made in a combo-box, I want the text to appear either in red or black. I tried using JavaScript for this ...

Trouble deploying Firebase Cloud Functions

I am attempting to implement the following two functions: exports.increaseWaitinglistCounters = functions.database .ref('waitinglists/$iid/$uid') .onCreate(async () => { await admin .database() .ref(`waitinglistCounters/$ii ...

When loading HTML using JavaScript, the CSS within the HTML is not properly processing. Leveraging Bootstrap 5 might help resolve

Currently utilizing bootstrap 5 for my project. I have a setup in index.html where I am loading the contents of nav.html using JavaScript. However, I am facing an issue wherein the CSS styling for the navbar is not being applied when loaded via JS. Strange ...

ReactJS - Common Mistakes in Writing Code

I'm a beginner in Javascript and struggling to resolve this issue. When I declare my 'params' variable with var, I encounter an error stating "[js] Unexpected token. A constructor, method, accessor, or property was expected." You can take a ...

How can I utilize the <v-for> and <v-checkbox> components in Vuetify to create a table format with multiple checkboxes displayed

Utilizing the VuetifyJs framework for VueJS, my goal is to showcase a checkbox in a table format based on an array of objects. The Desired Output looks like this: https://i.sstatic.net/veXGZ.png When 'All Users' is selected, all checkboxes shou ...

Is Ruby on Rails featured in Designmodo's Startup Framework Kit?

I'm curious if the Startup Framework Kit from Designmodo can be seamlessly incorporated into my Ruby on Rails project. While I've had success integrating their Flat-UI-Pro using a gem, I haven't come across one for the Startup Framework yet. ...

Obtain the HTTP response status code within a middleware function

I am currently developing an application where I want to create a custom logging system for every request made. For each request, I want to log the timestamp, method, route, and the response code sent to the client. Here is the code I have at the moment: ...

Drop-down selection triggering horizontal auto-scroll

Within my div element, I have a table with dropdowns. The div is set up to be horizontally scrollable. To create the dropdown functionality, I utilized Harvesthq Chosen. Let me provide some context. In Image 1, you'll notice that I've scrolled ...

How to retrieve an unknown JSON key in Vue.js when using v-for loop?

I have developed a code analysis tool and I am looking to display my JSON data in a Vue table. The challenge is that I need the JSON key, which represents the package/file name of the directory whose data I want to showcase. Below is an excerpt of the JSO ...

Personalize buttons using SweetAlerts 2 customization options

In order to adhere to the custom design provided to me, I am currently using SweetAlerts 2 for all dialog boxes that require confirmation or cancellation. Specifically, I require the cancel button to have a white background with teal text and a teal border ...

Implementing dynamic data filtering in Vue.js is a valuable feature that

I'm working on a Vuejs project where I need to filter out only the questions with reviewed:true and get the count of them. However, I'm encountering an error while using the code below: TypeError: question.reviewed.includes is not a function. Can ...

What is the best way to assign the value of a specific key in one array as the key in a different array?

I am attempting to retrieve the value feature_1 associated with the key name from the array data. I then aim to set feature_1 as the key of another array asset, with an array as its corresponding value. For example: //input: data: { name: "feature_1" ...

Utilizing JQuery AJAX to Submit a JSONP Form with File Attachments

I have been working on implementing a contact form for our clients who create websites with their own domains through us. As part of our services, we provide hosting and a web editor to help them build their websites. The contact form they include on their ...

`Need help setting the active class for a bootstrap navbar using Angular JS?`

In my bootstrap navbar, I have the following menu items: Home | About | Contact I'm looking to assign the active class to each menu item based on the current angular route. Specifically, how can I set class="active" when the angular route is at # ...

The connection between two arrays remains intact even after using the .push() method in JavaScript or Vue.js

I need help setting up two arrays containing dates. The first array should have the dates in string format, while the second array should contain the same dates but as date objects. methods: { test() { let employments = [ { begin: ...

What is the process for choosing all items and then canceling the selection in a

I utilized the information on this webpage to generate the following code snippet: https://getbootstrap.com/docs/5.0/forms/checks-radios/#indeterminate Upon clicking the checkbox with the ID of (flexCheckIndeterminate), all checkboxes located below it wil ...

What is the reason for TypeScript allowing this promise chain without any compilation errors?

Although I am still relatively new to Typescript, I find myself grappling with a particular issue that has been perplexing me. I am unsure why the following code snippet triggers a compilation error: // An example without Promises (does not compile) funct ...

Shared variables in Node.js allow for multiple users to access different entry points simultaneously

In the process of transitioning my node-js application from a single-tenant database to a multi-tenant database, I am facing some challenges. The application code is accessed through an express api and various services are run through different entrypoints ...