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?