Commit 18cc2186 authored by Bui Duc Tuan's avatar Bui Duc Tuan

check task exist and when page not found redirect page 404

parent af3fd7ec
<template>
<div class="container text-center mt-5">
<h1>404</h1>
<p>page not found.</p>
</div>
</template>
<script>
export default {
}
</script>
<style scoped>
h1{
font-size: 100px;
}
p{
font-size: 25px;
}
</style>
\ No newline at end of file
......@@ -32,17 +32,23 @@
</template>
<script>
import Vue from 'vue';
import VueAlertify from 'vue-alertify';
import Vue from "vue";
import VueAlertify from "vue-alertify";
Vue.use(VueAlertify);
export default {
created: function () {
if (localStorage.getItem("tasks")) {
this.tasks = JSON.parse(localStorage.getItem("tasks"));
}
if (this.tasks[this.id]) {
this.selected = this.tasks[this.id].status;
this.task = this.tasks[this.id].name;
} else {
this.$router.push("/");
this.$alertify.error('Task not found!');
}
},
......@@ -69,7 +75,7 @@ export default {
localStorage.setItem("tasks", JSON.stringify(this.tasks));
this.task = null;
this.$router.push("/");
this.$alertify.warning('Edit task successfully');
this.$alertify.warning("Edit task successfully");
},
},
};
......
import Task from './components/Task.vue';
import addTask from './components/addTask.vue';
import editTask from './components/editTask.vue';
import Error404 from './components/Error/404.vue';
export const routes = [
{ path: '/', name: 'Task', component: Task },
{ path: '/task/add', name: 'addTask', component: addTask },
{ path: '/task/edit/:id', name: 'editTask', component: editTask }
{ path: '/task/edit/:id', name: 'editTask', component: editTask },
{ path: '/404', name: 'Error404', component: Error404 },
{ path: '*', redirect: '/404' },
];
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment