fixed routing issue on logout
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, reactive, computed } from 'vue'
|
import { ref, reactive, computed } from 'vue'
|
||||||
import { postBook, extractFormErrorFromField } from './api.js'
|
import { postBook, extractFormErrorFromField } from './api.js'
|
||||||
import { useRouter, useRoute } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,15 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { RouterLink } from 'vue-router'
|
import { RouterLink } from 'vue-router'
|
||||||
import { useAuthStore } from './auth.store.js'
|
import { useAuthStore } from './auth.store.js'
|
||||||
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
const authStore = useAuthStore();
|
const authStore = useAuthStore();
|
||||||
|
const router = useRouter();
|
||||||
|
|
||||||
|
function logout() {
|
||||||
|
authStore.logout();
|
||||||
|
router.push('/');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { defineStore } from 'pinia';
|
import { defineStore } from 'pinia';
|
||||||
import { useRouter } from 'vue-router'
|
|
||||||
|
|
||||||
export const useAuthStore = defineStore('auth', {
|
export const useAuthStore = defineStore('auth', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
@@ -15,7 +15,6 @@ export const useAuthStore = defineStore('auth', {
|
|||||||
logout() {
|
logout() {
|
||||||
this.user = null;
|
this.user = null;
|
||||||
localStorage.removeItem('user');
|
localStorage.removeItem('user');
|
||||||
useRouter().push('/');
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,13 +1,8 @@
|
|||||||
import { createApp } from 'vue'
|
import { createApp } from 'vue'
|
||||||
import { createI18n } from "vue-i18n";
|
import { createI18n } from "vue-i18n";
|
||||||
import { createPinia } from 'pinia'
|
import { createPinia } from 'pinia'
|
||||||
import { createRouter, createWebHistory } from 'vue-router'
|
import { router } from './router.js'
|
||||||
import App from './App.vue'
|
import App from './App.vue'
|
||||||
import BooksBrowser from './BooksBrowser.vue'
|
|
||||||
import AddBook from './AddBook.vue'
|
|
||||||
import SignUp from './SignUp.vue'
|
|
||||||
import LogIn from './LogIn.vue'
|
|
||||||
import Home from './Home.vue'
|
|
||||||
|
|
||||||
import fr from './locales/fr.json';
|
import fr from './locales/fr.json';
|
||||||
import en from './locales/en.json';
|
import en from './locales/en.json';
|
||||||
@@ -21,19 +16,6 @@ const i18n = createI18n({
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
const routes = [
|
|
||||||
{ path: '/', component: Home },
|
|
||||||
{ path: '/books', component: BooksBrowser },
|
|
||||||
{ path: '/add', component: AddBook },
|
|
||||||
{ path: '/signup', component: SignUp },
|
|
||||||
{ path: '/login', component: LogIn },
|
|
||||||
]
|
|
||||||
|
|
||||||
export const router = createRouter({
|
|
||||||
history: createWebHistory(),
|
|
||||||
routes,
|
|
||||||
})
|
|
||||||
|
|
||||||
const pinia = createPinia()
|
const pinia = createPinia()
|
||||||
|
|
||||||
createApp(App).use(i18n).use(pinia).use(router).mount('#app')
|
createApp(App).use(i18n).use(pinia).use(router).mount('#app')
|
||||||
|
|||||||
20
front/src/router.js
Normal file
20
front/src/router.js
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import { createRouter, createWebHistory } from 'vue-router'
|
||||||
|
|
||||||
|
import BooksBrowser from './BooksBrowser.vue'
|
||||||
|
import AddBook from './AddBook.vue'
|
||||||
|
import SignUp from './SignUp.vue'
|
||||||
|
import LogIn from './LogIn.vue'
|
||||||
|
import Home from './Home.vue'
|
||||||
|
|
||||||
|
const routes = [
|
||||||
|
{ path: '/', component: Home },
|
||||||
|
{ path: '/books', component: BooksBrowser },
|
||||||
|
{ path: '/add', component: AddBook },
|
||||||
|
{ path: '/signup', component: SignUp },
|
||||||
|
{ path: '/login', component: LogIn },
|
||||||
|
]
|
||||||
|
|
||||||
|
export const router = createRouter({
|
||||||
|
history: createWebHistory(),
|
||||||
|
routes,
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user