From 8ff37f955e48a112ec448ab3b55d3efb0caec16d Mon Sep 17 00:00:00 2001 From: liamcottle Date: Thu, 13 Feb 2025 17:31:15 +1300 Subject: [PATCH] allow web hash history, but require device connection for some routes --- src/main.js | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main.js b/src/main.js index f4f257e..8f61686 100644 --- a/src/main.js +++ b/src/main.js @@ -1,9 +1,19 @@ import { createApp } from 'vue'; -import { createRouter, createMemoryHistory } from 'vue-router'; +import { createRouter, createWebHashHistory } from 'vue-router'; import vClickOutside from "click-outside-vue3"; import "./style.css"; import App from './components/App.vue'; +import GlobalState from "./js/GlobalState.js"; + +// helper function that force redirects to the main page if there is no device connection +function handleRouteThatRequiresDeviceConnection() { + if(!GlobalState.connection){ + return { + name: 'main', + }; + } +} const routes = [ { @@ -21,16 +31,18 @@ const routes = [ path: '/contacts/:publicKey/messages', props: true, component: () => import("./components/pages/ContactMessagesPage.vue"), + beforeEnter: handleRouteThatRequiresDeviceConnection, }, { name: "settings.radio", path: '/settings/radio', component: () => import("./components/pages/RadioSettingsPage.vue"), + beforeEnter: handleRouteThatRequiresDeviceConnection, }, ]; const router = createRouter({ - history: createMemoryHistory(), + history: createWebHashHistory(), routes: routes, });