Strange issue with Vue.js 2 router

Here is a snippet of my axios request code:

.then(function (response) {

    self.forms.process = false;

    if( response.data.redirect ){
        console.log(123);
        router.push({ name: response.data.redirect });
    }

})
.catch(function (error) {
    console.log(error.response.data);

When I remove router.push, there are no errors. However, when I use router.go instead, an error occurs at the console.log(error.response.data) line:

  • // 123 is printed by console.log before router.push here
  • Uncaught (in promise) TypeError: Cannot read property 'data' of undefined

I am struggling to figure out how to fix this bug.

Answer №1

It would be more appropriate to utilize self.$router.push rather than directly calling router.push

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

Using postMessage to communicate with the localstorage of an iframe from a separate domain

I have a question regarding the challenges of using localStorage for performance reasons and any potential workarounds. From what I gather, once a reference to localStorage is detected on a page (at compile time?), it blocks the thread to read data from di ...

Combine various hierarchies using a single JSON with d3.pack

I currently have a JSON file that I need to utilize in order to create three distinct hierarchy visualizations using d3.pack. This JSON file contains data for eventA (1 or 0) and eventB (1 or 0). Each individual leaf also possesses a unique ID. The hiera ...

restrict the maximum character count in regex

The string can consist of a single number or multiple numbers separated by "-", but the total character count must not exceed 6. Examples of valid strings 5 55-33 4444-1 1-4444 666666 Examples of invalid strings -3 6666- 5555-6666 My initial regex / ...

Navigating through a text field using the arrow keys

The arrow keys (left and right) are unable to navigate within a text field. Additionally, placing the cursor within a text field for editing is not possible as it jumps to the end every time a character is added. This issue is present in Chrome and IE, but ...

Implementing Multiple HTML Files Loading in QUnit

Currently, I am utilizing QUnit for unit testing JavaScript and jQuery. The structure of my HTML document is as follows: <!DOCTYPE html> <html> <head> <title>QUnit Test Suite</title> <script src="../lib/jquery.js">< ...

Creating a top-to-bottom pull effect on a single page, similar to the Android title bar, can be achieved using CSS3

Is there a way to achieve an effect in HTML that resembles the pull title bar animation from top to bottom in Android? Any suggestions on how to create this effect or what tools I would need? Currently, when I swipe, the page simply displays a following ...

Ways to dynamically fetch data in JavaScript from PHP

Looking to retrieve dynamic values from PHP within JS in a flexible manner. To explain further, I'll first display the image then the code: https://i.sstatic.net/hhaX6.png <div id=""> <table border="1" width="820" style="margin-left:15px;" ...

Defeat a JavaScript function or turn it into a Singleton Function

Is there a method to stop a running JavaScript function? Or is there a way to make sure that only one instance of the function runs at a time and any previous instances are removed upon restart? For example, if I call: _.defer(heavyDutyPaint); //How ca ...

Angular2's hidden feature isn't functioning properly

There is a common suggestion to use *ngIf better than [hidden] but in my scenario, I want to keep the element in the DOM without it being visible. In my component.html file, I have: <article #articleId id="bodyArticle" [hidden]="isClicked"></art ...

What causes parseInt to transform a value into infinity?

Here is what I'm working on: let s = '50'; let a = parseInt(s); console.log(a); //outputs 50 console.log(_.isFinite(a)); //outputs false I'm curious why parseInt turns 'a' into infinity when 'a' is set to 50? ...

Instructions for displaying typed chat messages on the screen using socket.io and node.js

I am currently developing a chat application using socket.io and node.js. I have successfully connected the server and both the socket.io and client-side socket.io are also connected. However, when I type a message on the localhost page and hit enter, noth ...

When using react, it is not possible to have a <span> element as a child of a <

I designed a custom select dropdown feature for use in a redux-form within a react-redux application. The dropdown functions well, with no performance issues, but I am encountering a warning in the browser. Warning: validateDOMNesting(...): <span> c ...

Building an API using .Net Core paired with a captivating VUE spa

I am currently working on hosting a Vue SPA client within the wwwroot folder of my API. I have successfully set up build scripts to compile and place the SPA into the folder. Additionally, I am utilizing app.UseSpa() to handle requests during development. ...

Unveil the power of the "Enter" key with these jQuery hacks

Is there a way to prevent the Enter key from being counted as a character when disabling the submit button until something is entered in a TextArea? This functionality is achieved using the Count.js.coffee script. $(document).ready -> $(".cmnt_btn") ...

Can Vue Router be configured to show varying layouts depending on the parameter provided?

Is it feasible for Vue Router to exhibit distinct layouts depending on the parameter provided in a URL? Take into account the following URLs: /admin/forms/pending /admin/forms/approved /admin/forms/declined /admin/forms/categories The first three links ...

Activating the Speech Recognition feature in a form triggers the submission of a post

Currently, I am integrating webkitspeechRecongition into a form to allow users to enter data using their voice by pressing a button. However, a challenge arises when the call is triggered by a button within the form as it results in a post/submit action th ...

Animating HTML elements with JavaScript and CSS when hovering the mouse

Recently, I stumbled upon the SkyZone website and was impressed by the captivating JavaScript/CSS/HTML effects they used. I was inspired to include similar effects on my own website. (Visit the Home Page) One noteworthy feature on their website is the n ...

I am looking for a sample code for Tizen that allows scrolling of a <div> element using the bezel

Seeking a functional web application in Tizen that can scroll a div using the rotating bezel mechanism. I have dedicated several hours to getting it to work without success. I keep revisiting the same resources for the past three days: View Link 1 View Li ...

The MongoDB regex is failing to provide the expected outcome

I'm facing an issue with searching data in MongoDB. I have a table with approximately 5000 entries of data that need to be searched based on multiple columns with specific priority criteria. The first priorities for the search are symbol, name, co_nam ...

Tips on using Visual Studio Code to troubleshoot Angular 4 unit tests

I am working on an Angular 4 project with Material design in Visual Studio Code. The setup is done using angular/cli. Currently, I have been writing unit tests using Karma and Jasmine. However, when trying to debug the tests by setting breakpoints, it doe ...