新增URL重定向检查功能,确保用户在非目标域名访问时自动重定向到官方域名,提升用户体验和安全性。

This commit is contained in:
zihanjian
2025-06-03 18:10:38 +08:00
parent 075b4882f8
commit 6b0710fc82

View File

@@ -752,6 +752,41 @@ export default function Home() {
setIsMounted(true);
}, []);
// 添加URL重定向检查
useEffect(() => {
// 检查是否在浏览器环境中
if (typeof window !== 'undefined') {
const currentUrl = window.location.href;
const targetDomain = 'https://perlerbeads.zippland.com/';
// 检查当前URL是否不是目标域名
if (!currentUrl.startsWith(targetDomain)) {
console.log(`当前URL: ${currentUrl}`);
console.log(`目标URL: ${targetDomain}`);
console.log('正在重定向到官方域名...');
// 保留当前路径和查询参数
const currentPath = window.location.pathname;
const currentSearch = window.location.search;
const currentHash = window.location.hash;
// 构建完整的目标URL
let redirectUrl = targetDomain;
// 如果不是根路径,添加路径
if (currentPath && currentPath !== '/') {
redirectUrl = redirectUrl.replace(/\/$/, '') + currentPath;
}
// 添加查询参数和哈希
redirectUrl += currentSearch + currentHash;
// 执行重定向
window.location.replace(redirectUrl);
}
}
}, []); // 只在组件首次挂载时执行
// --- Download function (ensure filename includes palette) ---
const handleDownloadRequest = (options?: GridDownloadOptions) => {
// 调用移动到utils/imageDownloader.ts中的downloadImage函数