forked from jsnbuchanan/crowd-funder-for-time-pwa
Multi-build support; tested successfully for Electron
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import {
|
||||
createRouter,
|
||||
createWebHistory,
|
||||
createMemoryHistory,
|
||||
NavigationGuardNext,
|
||||
RouteLocationNormalized,
|
||||
RouteRecordRaw,
|
||||
@@ -21,6 +22,9 @@ const enterOrStart = async (
|
||||
// one of the few times we use accountsDBPromise directly; try to avoid more usage
|
||||
const accountsDB = await accountsDBPromise;
|
||||
const num_accounts = await accountsDB.accounts.count();
|
||||
|
||||
console.log("Number of accounts: ", num_accounts);
|
||||
|
||||
if (num_accounts > 0) {
|
||||
next();
|
||||
} else {
|
||||
@@ -255,12 +259,26 @@ const routes: Array<RouteRecordRaw> = [
|
||||
},
|
||||
];
|
||||
|
||||
const isElectron = window.location.protocol === "file:"; // Check if running in Electron
|
||||
const initialPath = isElectron
|
||||
? window.location.pathname.replace("/dist-electron/index.html", "/")
|
||||
: window.location.pathname;
|
||||
|
||||
const history = isElectron
|
||||
? createMemoryHistory() // Memory history for Electron
|
||||
: createWebHistory("/"); // Add base path for web apps
|
||||
|
||||
/** @type {*} */
|
||||
const router = createRouter({
|
||||
history: createWebHistory(import.meta.env.BASE_URL),
|
||||
history,
|
||||
routes,
|
||||
});
|
||||
|
||||
console.log("Initial URL:", initialPath);
|
||||
|
||||
// Replace initial URL to start at `/` if necessary
|
||||
router.replace(initialPath || "/");
|
||||
|
||||
const errorHandler = (
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
error: any,
|
||||
@@ -278,4 +296,12 @@ const errorHandler = (
|
||||
|
||||
router.onError(errorHandler); // Assign the error handler to the router instance
|
||||
|
||||
router.beforeEach((to, from, next) => {
|
||||
console.log("Navigating to view:", to.name);
|
||||
console.log("From view:", from.name);
|
||||
next();
|
||||
});
|
||||
|
||||
console.log("Initial URL:", window.location.pathname);
|
||||
|
||||
export default router;
|
||||
|
||||
Reference in New Issue
Block a user