From 0e1712ebbe312067b9b8a25113998ff3ddf3fce6 Mon Sep 17 00:00:00 2001 From: Cagatay Civici Date: Wed, 23 Feb 2022 23:08:45 +0300 Subject: [PATCH] Default to Lara when navigation to home --- src/main.js | 7 ++++++- src/router/index.js | 7 +++++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/main.js b/src/main.js index 66ee251cc..03bf8cee8 100644 --- a/src/main.js +++ b/src/main.js @@ -105,6 +105,8 @@ import AppDemoActions from './AppDemoActions'; import AppDocumentation from './AppDocumentation'; import CodeHighlight from './AppCodeHighlight'; +import EventBus from '@/AppEventBus'; + import './assets/styles/primevue.css'; import 'primeflex/primeflex.css'; import 'primeicons/primeicons.css'; @@ -112,7 +114,10 @@ import 'prismjs/themes/prism-coy.css'; import './assets/styles/flags.css'; router.beforeEach(function (to, from, next) { - window.scrollTo(0, 0); + if (to.name === 'home' && from.name) { + const newTheme = app.config.globalProperties.$appState.darkTheme ? 'lara-dark-indigo' : 'lara-light-indigo'; + EventBus.emit('theme-change', { theme: newTheme, dark: app.config.globalProperties.$appState.darkTheme }); + } next(); }); diff --git a/src/router/index.js b/src/router/index.js index f71703828..d16c5cc99 100644 --- a/src/router/index.js +++ b/src/router/index.js @@ -840,8 +840,11 @@ const routes = [ const router = createRouter({ history: createWebHashHistory(), routes, - scrollBehavior () { - return { left: 0, top: 0 }; + scrollBehavior (to, from, savedPosition) { + if (savedPosition) + return savedPosition + else + return { left: 0, top: 0 }; } });