Why isn't the $route.router.go() function working in Vue.js Router?

Why is the redirect to the page not working with vue-router version 0.7.13 + SweetAlert? The code I am using in Laravel 5.3 looks like this:

This is how article.blade.php looks:

...
<a href="#" v-on:click.prevent="deleteArticle('/articles/{{ $article->id }}/delete')">Delete</a>
...

Here is my app.js:

window.Vue = require('vue');
window.VueRouter = require('vue-router');
Vue.use(VueRouter);

var article_form = new Vue({
  el: '#article_form',
  data: {
    ...
  },
  methods: {
    ...
    ...
    deleteArticle: function (url) { // Click Delete button
      var self = this;
      swal({
        title: "Are you sure?",
        text: "You will not be able to recover this imaginary file!",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "Yes, delete it!",
        closeOnConfirm: false
      }, function () { // Click Yes button
        self.$http.delete(url).then(function () {
          swal({
            title: "Deleted!",
            text: "Your imaginary file has been deleted.",
            type: "success"
          }, function () { // After click ОК must be redirect
            self.$route.router.go('/articles');
          });
        });
      });
    }
  }
});

And here is package.json:

{
  "private": true,
  "scripts": {
    "prod": "gulp --production",
    "dev": "gulp watch"
  },
  "devDependencies": {
    "gulp": "^3.9.1",
    "laravel-elixir": "^6.0.0-14",
    "laravel-elixir-webpack-official": "^1.0.9",
    "vue-resource": "^1.0.3"
  },
  "dependencies": {
    "sweetalert": "^1.1.3",
    "vue": "^1.0.28",
    "vue-router": "^0.7.13"
  }
}

The error message from OS X Safari console says:

TypeError: undefined is not an object (evaluating 'self.$route.router')
.

I have also tried using self.$router.go('/articles'), but it results in the same error. It seems like $route (or $router) is being treated as undefined.

What could be causing this issue?

Answer №1

Make sure you don't miss out on installing the crucial plugin:

const VueRouter = require('vue-router');
Vue.use(VueRouter);

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

What is the best way to modify a nested json value when you have the specific key?

I'm working with a nested json object structured like this: { "fontweight": { "primary": { "weight1": { "value": "Regular", "type": "fontWeights" } ...

Why is the click event not working in IE8 for JavaScript / jQuery?

There seems to be an issue with the program not functioning properly in IE8 for some users. The website in question is an English course where certain individuals are experiencing difficulty clicking on the correct answers. To view a demonstration of this ...

When the jQuery document is ready, it typically returns null, but the console can still access and display

I have encountered an issue while working on a solution within a CMS (EPiServer). When I utilize console.log to check my object, it displays a null value. $(document).ready(function () { console.log("$('.EPiRequester').html() =" + $('. ...

Cloning a repository using the GitHub API via client-side Javascript and OAuth.io

I am currently developing client-side Javascript code that will fork a specified GitHub repository. To achieve this, I am utilizing the OAuth.io service to obtain an OAuth token with the necessary API scopes of "public_repo" and "repo". For accessing the ...

The Axios.delete encountered a problem while attempting to delete data from the database, showing the error message "Error:

My current tech stack includes Vue 2.3, MongoDB, Node.js, Express, and Handlebars. Initially, I was using handlebars but now I want to switch to Vue. <form class="center" action="/audioannotations/delete/{{_id}}?_method= ...

Triggering a Vue callback once a click method has been successfully executed

Currently, I am dealing with a list containing @click events attached to individual elements. Whenever a user clicks on an element, I am dynamically generating additional elements using v-if. The challenge I am facing is that I need to manipulate these dyn ...

How can a parent directive be updated in a decoupled manner from a dynamically generated view/controller that acts as a child of the parent?

I am working on an app that includes window instances. These instances can have multiple windows and each window can contain multiple views. The views are considered as children of each window instance. Both the windows and view creator are directives with ...

Email delivery confirmation tests for Event Listeners

As someone who is new to testing, I could really use some assistance. Let's start with the code snippet from my App directory in Laravel 5.5. // controller public function store(Request $request) { $foo = new Foo($request->only([ ...

What is the best way to incorporate data from my API into my component?

App.js import { Text, View, Button, FlatList } from 'react-native'; import { useEffect, useState } from 'react'; import * as React from 'react'; const API = 'https://randomuser.me/api/users/'; const User = (props) ...

What is the best way to notify an XML file using jQuery?

I am encountering an issue with a login api when trying to send an xml document. The error occurs when including '<?', but I need to send the whole XML with it. Can someone assist me in sending the complete XML using a different method or type ...

Explore a vast array of items in a collection

I have a massive collection of various objects that I need to sift through. With over 60,000 elements, the search operation can sometimes be painfully slow. One typical object in this array has the following structure: { "title": "title" "company": ...

Tips for managing and identifying canceled requests in an Angular HTTP interceptor

Having trouble handling cancelled requests in my http interceptor. Despite trying various methods from SO, I can't seem to catch it. Here is an example of how my interceptor looks: public intercept(req: HttpRequest<any>, next: HttpHandler) { ...

After submitting my form, the Bootstrap Modal does not hide as intended by my Ajax

I am facing an issue with my webpage that displays 6 Bootstrap Cards in 3 columns. Each card contains an image, name, description, and a footer button. When a user clicks on the button, a Bootstrap Modal opens with specific data fetched from a SQL row by I ...

A combination of promises with async/await can lead to undefined return values

Currently facing an issue where my Async call to the database is returning undefined. The function "findOne" should retrieve one row from the database, but the .then(...) function is executing before the row is actually returned. I've attempted vario ...

Locating marker coordinates on the screen with AR.js

After implementing the code below, I successfully retrieved the marker's position: this.marker.object3D.getWorldPosition(vector); Now, I am eager to understand if there is a way to convert this position (x,y,z) into its corresponding screen coordinat ...

I am encountering an issue with CreateJS where I receive the error message: "createjs is not defined"

Looking for assistance with my createJS issue. var stage = new createjs.Stage(canvas); Encountering the following error : angular.js:13642 ReferenceError: createjs is not defined, even though I have EaselJS in my bower-components. Appreciate any hel ...

Update the router URL without switching pages, yet still record it in the browser history

One of the features on my search page allows users to perform searches and view results. Initially, I faced a challenge in updating the router URL without navigating, but I managed to overcome this by utilizing the "Location" feature. In my ngOnInit meth ...

Is it possible for me to dictate the sequence in which javascript / jQuery events are triggered?

Issue at Hand In my asp.net webform, I have a grid where users can update textboxes. These updates trigger a WebMethod call, updating the rest of the row without saving. To save the changes, users must click a save button. While this system works well in ...

What is the best way to relocate a child component to a different parent in React?

I have a list of child components with checkboxes, and when a checkbox is clicked, I want to move that child component inside another div. Below is an illustration of how my app should look. I need to select student names and shift them up under the "Pres ...

Convert numerical values to currency format

Here is a number 5850 that I would like to format as currency. Format Example 1: 5850 => $58.50 Format Example 2: 9280 => $92.80 I am utilizing the function below: Number.prototype.formatMoney = function(decPlaces, thouSeparator, decSeparat ...