import { createRouter, createWebHashHistory, createWebHistory, NavigationGuardNext, RouteLocationNormalized } from 'vue-router' import LayoutDefault from '@/views/layouts/LayoutDefault.vue' import { isElectron } from './utils/envUtil' const isFileProtocol = () => window.location.protocol === 'file:' const guardElectronAccess = ( to: RouteLocationNormalized, from: RouteLocationNormalized, next: NavigationGuardNext ) => { if (isElectron()) { next() } else { next('/') } } const router = createRouter({ history: isFileProtocol() ? createWebHashHistory() : // Base path must be specified to ensure correct relative paths // Example: For URL 'http://localhost:7801/ComfyBackendDirect', // we need this base path or assets will incorrectly resolve from 'http://localhost:7801/' createWebHistory(window.location.pathname), routes: [ { path: '/', component: LayoutDefault, children: [ { path: '', name: 'GraphView', component: () => import('@/views/GraphView.vue') }, { path: 'server-start', name: 'ServerStartView', component: () => import('@/views/ServerStartView.vue'), beforeEnter: guardElectronAccess }, { path: 'install', name: 'InstallView', component: () => import('@/views/InstallView.vue'), beforeEnter: guardElectronAccess }, { path: 'welcome', name: 'WelcomeView', component: () => import('@/views/WelcomeView.vue'), beforeEnter: guardElectronAccess } ] } ], scrollBehavior(to, from, savedPosition) { if (savedPosition) { return savedPosition } else { return { top: 0 } } } }) export default router