import { createRouter, createWebHistory } from 'vue-router'; import Layout from './layouts/Main.vue'; const accountData = window.loyalty_suite_account_data || {}; const normalizePath = (urlOrPath: string | undefined | null): string => { if (!urlOrPath) return '/'; let path = urlOrPath; try { if (path.startsWith('http://') || path.startsWith('https://')) { path = new URL(path).pathname; } } catch (e) { } path = path.replace(/\/+$/, ''); return path || '/'; }; const basePath = normalizePath(accountData.basePath || '/'); const shareBasePath = normalizePath(accountData.shareBase || ''); const currentPath = normalizePath(window.location.pathname); const isShareStandalone = !!shareBasePath && shareBasePath !== basePath && currentPath === shareBasePath; const routes = isShareStandalone ? [ { path: '/', component: () => import('./views/Share.vue'), }, ] : [ { path: '/', component: Layout, children: [ { path: '', component: () => import('./views/Profile.vue'), }, { path: '/ranks', component: () => import('./views/Ranks.vue'), }, { path: '/achievements', component: () => import('./views/Achievements.vue'), }, { path: '/my-achievements', component: () => import('./views/MyAchievements.vue'), }, { path: '/challenges', component: () => import('./views/Challenges.vue'), }, { path: '/my-challenges', component: () => import('./views/MyChallenges.vue'), }, { path: '/my-rewards', component: () => import('./views/MyRewards.vue'), }, { path: '/wallet/:id', component: () => import('./views/WalletSingle.vue'), props: true, }, { path: '/achievement/:id', component: () => import('./views/AchievementSingle.vue'), props: true, }, { path: '/rank/:id', component: () => import('./views/RankSingle.vue'), props: true, }, { path: '/challenge/:id', component: () => import('./views/ChallengeSingle.vue'), props: true, }, { path: '/share', component: () => import('./views/Share.vue'), props: true, }, ], }, ]; const router = createRouter({ history: createWebHistory( isShareStandalone ? shareBasePath : basePath ), routes, scrollBehavior() { return { left: 0, top: 0 }; }, }); export default router;