import { boot } from 'quasar/wrappers'; import { useUserStore } from 'src/vueLib/login/userStore'; export default boot(async ({ router }) => { const userStore = useUserStore(); // Restore logic after router is ready but before navigation router.isReady().then(() => { const lastRoute = sessionStorage.getItem('lastRoute'); const currentPath = router.currentRoute.value.fullPath; // Restore only if: // - we’re on root ("/" or "/#/"), and // - a last route exists, and // - the user is authenticated if ( lastRoute && ['/', '/#/', '/#/index.html'].includes(currentPath) && userStore.isAuthenticated ) { router.replace(lastRoute).catch(() => {}); } }); // Save the route after every successful navigation router.afterEach((to) => { // Don't save login page as "last route" if (to.path !== '/login' && to.path !== '/') { sessionStorage.setItem('lastRoute', to.fullPath); } }); });