debug
This commit is contained in:
@@ -75,22 +75,30 @@ document.addEventListener("DOMContentLoaded", function () {
|
||||
});
|
||||
|
||||
function handleRedirect() {
|
||||
// 获取当前路径和主机名
|
||||
const strCurrentPath = window.location.pathname || '/index.html'; // 如果路径为空,默认设置为 /index.html
|
||||
const strCurrentHost = window.location.origin;
|
||||
const { pathname, origin, search } = window.location;
|
||||
|
||||
// Normalize pathname by replacing multiple slashes with a single slash
|
||||
const normalizedPath = pathname.replace(/\/+/g, '/');
|
||||
const strCurrentPath = normalizedPath || '/index.html';
|
||||
|
||||
// Build URL with proper slash handling
|
||||
const buildUrl = (path) => {
|
||||
// Ensure path starts with a single slash and remove duplicate slashes
|
||||
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
|
||||
return `${origin}${cleanPath}${search}`;
|
||||
};
|
||||
|
||||
if (isMobile()) {
|
||||
// 移动端逻辑
|
||||
// Mobile logic: Redirect PC paths to mobile paths
|
||||
if (strCurrentPath.startsWith(strPcPath)) {
|
||||
// 如果路径包含 "/pc/",去除 "/pc/"
|
||||
const newPath = strCurrentPath.replace(strPcPath, '/'); // 去除 "/pc/"
|
||||
window.location.href = `${strCurrentHost}${newPath}`;
|
||||
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
} else {
|
||||
// PC 端逻辑
|
||||
// PC logic: Redirect non-PC paths to PC paths
|
||||
if (!strCurrentPath.startsWith(strPcPath)) {
|
||||
// 如果路径不包含 "/pc/",添加 "/pc/"
|
||||
window.location.href = `${strCurrentHost}${strPcPath}${strCurrentPath}`;
|
||||
const newPath = `${strPcPath}${strCurrentPath === '/' ? '' : strCurrentPath}`;
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user