Encountering Vue js router issues post login validation

I am a beginner with vue and I recently created a small vue app on codesandbox:

https://codesandbox.io/s/vue-template-fjd4i

However, I am facing issues with routing. Here is how to reproduce the problem:

  1. Click on Login and enter any credentials
  2. You should now be on the Board page
  3. Click on the Statistics page
  4. Instead of the Statistics page, I am redirected to the Signup page. I am unsure why this is happening.

To update the navbar after logging in, I am using EventBus in event-bus.js:

// EventBus.js
import Vue from "vue";
export default new Vue();

When I am logged in (on the Board page) and click on Statistics, I noticed that the router's beforeEach function in router/index.js displays incorrect information:

router.beforeEach((to, from, next) => {
  console.log("///////");
  console.log(from);
  console.log(to);
  console.log(next);
  console.log("///////");

Instead of receiving the Statistics route in the to variable, I am getting the Signup route. Can someone please assist me with this issue?

Answer №1

If you are experiencing this issue, it may be because your route definition utilizes async loading with import(...), and the chunks have been named the same. Take a moment to review the comments declaring the names in your routes.

Additionally, double-check that the Statistics route is indeed returning the correct component. Have you copied and pasted accurately?

Answer №2

The issue stemmed from the use of <a> tags, inexplicably causing conflicts with vue routing. To resolve this, I made the following adjustment:

<router-link v-if="is_logged" tag="li" :to="{ name: 'Statistics' }">
  <a>Statistics</a>
</router-link>

In order to fix it, I revised it to:

<li v-if="is_logged"><router-link tag="a" :to="{ name: 'Statistics' }">
  Statistics
</router-link></li>

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

Struggling to display the array after adding a new item with the push method

Seeking assistance in JavaScript as a newcomer. I have written some code to print an array once a new item is added, but unfortunately, it's not displaying the array. I am puzzled as there are no errors showing up in the console either. In my code, I ...

Populate a database with information collected from a dynamic form submission

I recently created a dynamic form where users can add multiple fields as needed. However, I'm facing a challenge when it comes to saving this data into the database. You can view a similar code snippet for my form here. <form id="addFields" me ...

How can you use v-if condition in HTML with minimal code?

Trying to determine whether to create a <button> or <a> based on the href attribute. Unable to share the actual code due to the use of custom components, but a simplified version looks like this: <a v-if="href" class="btn" v-on:click="click ...

Event handlers in JQuery are not connected through breadcrumb links

Wondering how to ensure that the click handler is always attached in my Rails 4.1 app where I am using JQuery-ujs to update cells in a table within the comments#index view. In my comments.js.coffee file, I have the following code snippet: jQuery -> ...

Best practices for implementing the map function with TypeScript

I'm currently working on mapping types in a DB using the Map function in JavaScript. This is my first time trying to do this, and I'm eager to learn but I've hit a roadblock. Here is the structure of the DB: const db = { data: [ { ...

React JS: Incorporating Multiple Placeholder Objects within Components

Apologies if this question is a duplicate, but I haven't found any helpful answers yet. I'm new to React and JavaScript. I am looking to include multiple objects inside a component: For example: src={url} name={text} subTitle={subtext} My in ...

Error TS2339 encountered in ngx-uploader: There is no property called 'lastModifiedDate' on the type 'File'

An issue has arisen in the code at node_modules/ngx-uploader/src/ngx-uploader/classes/ngx-uploader.class.ts(112,32): error TS2339: Property 'lastModifiedDate' is not found on type 'File'. Encountered this error while updating my An ...

What is the most effective method for nesting loops in NodeJS and Mocha?

Currently, I am attempting to create a loop within a loop in my NodeJS code, but I seem to be getting lost along the way. The results are not as expected - sometimes callbacks are triggered twice and so on. My approach involves using the async module. I wo ...

Displaying JSON data within a div section using Ajax and jQuery is not possible

I have generated a JSON in a specific format from an external PHP file: [ { "title": "Welcome!", "description": "The world has changed dramatically..", "image": "img/strawberry-wallpaper.jpg" } ] I am trying to use this data to populate a par ...

Issues with changing background colors using Jquery animate

I am attempting to create a fading background color effect when a button is clicked. Currently, I can change the background color using this code: $("#" + lblqty).css("background","#e9f1ff"); However, when I try to use the animate function as shown below ...

Displaying a progress bar while fetching data in Vue: A step-by-step guide

I am working on developing a progress bar using vue js and bootstrap for my desktop application. Within the template, I have the code that will generate the necessary markup: <div class="container-fluid p-0 vh-100" v-if="isLoading&quo ...

Using Fullcalendar Moment to retrieve the current time plus an additional 2 hours

Trying to tackle this seemingly simple task using moment.js in conjunction with Fullcalendar. My goal is to retrieve the current time and then add two hours to it. Within the select method (or whatever terminology you prefer), I currently have: select: f ...

Three.js not rendering any objects, only displaying a blank black screen

I've encountered a similar issue with a few of my other three.js codes. I've set up the JavaScript within HTML, but the objects aren't appearing on the screen. Every time I run the file, it just shows a black screen. The file is supposed to ...

Is it possible to automatically reload the previous link when the back button of the browser is clicked?

I am working on a website where the main content is loaded using jQuery Ajax based on the selected menu item. When a menu item is selected, the URL changes according to this pattern: http://host/domain/index.php?pageid=page In this scenario, the 'p ...

What is the best way to transfer data from my browser to the backend of my application?

I am currently working on developing a basic weather application using Express and Node.js. To accomplish this, I need to automatically retrieve the latitude and longitude of the user. While I understand how to achieve this through HTML5 Geolocation in t ...

Mastering the ng-if directive in Angular can help you easily display or hide content based on boolean

Having trouble figuring out what to insert in the last span element where it mentions "I_DO_NOT_KNOW", here is the markup provided: <div class="row"> <div class="key" translate>Label</div> <div class="value form-group"> < ...

Harness the power of Bootstrap 5.3 color modes based on the user's browser

It has come to my attention that Bootstrap 5.3 introduces support for a customizable color scheme, allowing me to personalize various key features. Interestingly, the default dark theme now relies on the explicitly defined bs-theme data attribute rather t ...

Arrow functions do not function properly with Typescript decorators

I've created a typescript decorator factory that logs the total time taken to execute a function, along with the actual function execution results and parameters passed to the decorator. For example: export function performanceLog(...args: any[]) { ...

Enhancing Request JSON Body Validation in Next.js 14 API Handler

I'm currently in the process of developing an API for my iOS application using Next.js 14. I have managed to get it up and running successfully, however, I am facing some challenges when it comes to properly validating the body of a request. ESLint is ...

"Unlocking the Power of Material UI withStyles() in React JS: Mixing and Matching Styles for Stunning

I am working with the following code snippets: const styles = theme => ({root: {backgroundColor: '#000000'}) const styles2 = theme => ({root: {backgroundColor: '#fff'}) In my React component, I am using export default compose( ...