fixed routing issue on logout

This commit is contained in:
2025-10-09 00:56:46 +02:00
parent 4f1452e0d9
commit 2c6d0859f6
5 changed files with 30 additions and 22 deletions

View File

@@ -1,7 +1,7 @@
<script setup>
import { ref, reactive, computed } from 'vue'
import { postBook, extractFormErrorFromField } from './api.js'
import { useRouter, useRoute } from 'vue-router'
import { useRouter } from 'vue-router'
const router = useRouter();

View File

@@ -1,8 +1,15 @@
<script setup>
import { RouterLink } from 'vue-router'
import { useAuthStore } from './auth.store.js'
import { useRouter } from 'vue-router'
const authStore = useAuthStore();
const router = useRouter();
function logout() {
authStore.logout();
router.push('/');
}
</script>
<template>

View File

@@ -1,5 +1,5 @@
import { defineStore } from 'pinia';
import { useRouter } from 'vue-router'
export const useAuthStore = defineStore('auth', {
state: () => ({
@@ -15,7 +15,6 @@ export const useAuthStore = defineStore('auth', {
logout() {
this.user = null;
localStorage.removeItem('user');
useRouter().push('/');
}
}
});

View File

@@ -1,13 +1,8 @@
import { createApp } from 'vue'
import { createI18n } from "vue-i18n";
import { createPinia } from 'pinia'
import { createRouter, createWebHistory } from 'vue-router'
import { router } from './router.js'
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 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()
createApp(App).use(i18n).use(pinia).use(router).mount('#app')

20
front/src/router.js Normal file
View 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,
})