From 657759e6a7f9f24cd5e6599ef7223f36e71b0108 Mon Sep 17 00:00:00 2001 From: Less Date: Mon, 9 Dec 2024 18:17:49 +0800 Subject: [PATCH] feat: redirect v1 URL paths to v2 (#1024) * feat: redirect v1 URL paths to v2 * chore: update v1 URLs to .box * chore: redirect strategy and playground to v1 site --- apps/ui/src/components/Site/Footer.vue | 2 +- apps/ui/src/networks/offchain/index.ts | 4 +-- apps/ui/src/routes/index.ts | 40 +++++++++++++++++++++++++- apps/ui/src/views/My/Explore.vue | 4 ++- apps/ui/src/views/Settings/Spaces.vue | 2 +- 5 files changed, 46 insertions(+), 6 deletions(-) diff --git a/apps/ui/src/components/Site/Footer.vue b/apps/ui/src/components/Site/Footer.vue index 969f55189..d31940d87 100644 --- a/apps/ui/src/components/Site/Footer.vue +++ b/apps/ui/src/components/Site/Footer.vue @@ -34,7 +34,7 @@ const SOCIALS = [ Explore spaces
- + Create a space diff --git a/apps/ui/src/networks/offchain/index.ts b/apps/ui/src/networks/offchain/index.ts index 08e432458..3db38e889 100644 --- a/apps/ui/src/networks/offchain/index.ts +++ b/apps/ui/src/networks/offchain/index.ts @@ -13,8 +13,8 @@ const HUB_URLS: Partial> = { 's-tn': 'https://testnet.hub.snapshot.org/graphql' }; const SNAPSHOT_URLS: Partial> = { - s: 'https://snapshot.org', - 's-tn': 'https://testnet.snapshot.org' + s: 'https://v1.snapshot.box', + 's-tn': 'https://testnet.v1.snapshot.box' }; const CHAIN_IDS: Partial> = { s: 1, diff --git a/apps/ui/src/routes/index.ts b/apps/ui/src/routes/index.ts index 4572d4026..1b7cafe6c 100644 --- a/apps/ui/src/routes/index.ts +++ b/apps/ui/src/routes/index.ts @@ -1,6 +1,7 @@ import { createRouter, createWebHashHistory } from 'vue-router'; import SplashScreen from '@/components/Layout/SplashScreen.vue'; -import defaultRoutes from './default'; +import { metadataNetwork } from '@/networks'; +import defaultRoutes from '@/routes/default'; const { resolved } = useWhiteLabel(); @@ -32,4 +33,41 @@ const router = createRouter({ } }); +// Add a global navigation guard for URL redirection +router.beforeEach((to, _from, next) => { + let redirectPath: string | null = null; + + // Match and redirect paths like "/safe.eth/settings" to "/s:safe.eth/settings" + const domainMatch = to.path.match(/^\/([^:\/]+?\.[^:\/]+)(\/.*)?$/); + if (domainMatch) { + const domain = domainMatch[1]; + const rest = domainMatch[2] || ''; + redirectPath = `/${metadataNetwork}:${domain}`; + if (rest && !/^\/about$/.test(rest)) { + redirectPath += rest; + } + } + + // Match and redirect paths like "/delegate/safe.eth" to "/s:safe.eth/delegates" + const delegateMatch = to.path.match(/^\/delegate\/([^:\/]+?\.[^:\/]+)$/); + if (delegateMatch) { + const domain = delegateMatch[1]; + redirectPath = `/${metadataNetwork}:${domain}/delegates`; + } + + // Match and redirect "/strategy/*" or "/playground/*" to v1.snapshot.box + if (to.path.startsWith('/strategy/') || to.path.startsWith('/playground/')) { + const newPath = to.path.replace(/^\/(strategy|playground)/, '/#$1'); + window.location.href = `https://v1.snapshot.box${newPath}`; + return; + } + + // Perform the redirection if a match is found + if (redirectPath) { + next({ path: redirectPath, replace: true }); + } else { + next(); + } +}); + export default router; diff --git a/apps/ui/src/views/My/Explore.vue b/apps/ui/src/views/My/Explore.vue index 95a4904a1..9d9b9553c 100644 --- a/apps/ui/src/views/My/Explore.vue +++ b/apps/ui/src/views/My/Explore.vue @@ -180,7 +180,9 @@ onMounted(() => { diff --git a/apps/ui/src/views/Settings/Spaces.vue b/apps/ui/src/views/Settings/Spaces.vue index 209d746ed..4900f2894 100644 --- a/apps/ui/src/views/Settings/Spaces.vue +++ b/apps/ui/src/views/Settings/Spaces.vue @@ -71,7 +71,7 @@ watch(