debug
This commit is contained in:
@@ -74,22 +74,42 @@ 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;
|
||||
|
||||
// 规范化路径名,将多个斜杠替换为单个斜杠
|
||||
const normalizedPath = pathname.replace(/\/+/g, '/');
|
||||
var strCurrentPath = normalizedPath || '/index.html';
|
||||
const arrPcPathUrl = ['/pc', '/web', '/desktop', '/index', '/shouye', '/zhuomian', '/windows']; // 所有模板的 PC 目录
|
||||
// 构建URL,确保斜杠正确
|
||||
const buildUrl = (path) => {
|
||||
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
|
||||
return `${origin}${cleanPath}${search}`;
|
||||
};
|
||||
|
||||
// 获取当前路径的第一个目录
|
||||
var firstSegment = strCurrentPath.split('/')[1] || '';
|
||||
|
||||
// 判断当前路径的第一个目录是否在其它模板的 PC 目录中
|
||||
const isInPcPathArray = arrPcPathUrl.some(pcPath => firstSegment.startsWith(pcPath.replace('/', '')));
|
||||
|
||||
if (isMobile()) {
|
||||
// 移动端逻辑
|
||||
if (strCurrentPath.startsWith(strPcPath)) {
|
||||
// 如果路径包含 "/pc/",去除 "/pc/"
|
||||
const newPath = strCurrentPath.replace(strPcPath, '/'); // 去除 "/pc/"
|
||||
window.location.href = `${strCurrentHost}${newPath}`;
|
||||
// 如果第一个目录 在pc 模板里面 则删除替换成空
|
||||
if (isInPcPathArray) {
|
||||
const newPath = strCurrentPath.replace(firstSegment, '');
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
|
||||
} else {
|
||||
// PC 端逻辑
|
||||
if (!strCurrentPath.startsWith(strPcPath)) {
|
||||
// 如果路径不包含 "/pc/",添加 "/pc/"
|
||||
window.location.href = `${strCurrentHost}${strPcPath}${strCurrentPath}`;
|
||||
|
||||
if (!isInPcPathArray) {
|
||||
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
|
||||
window.location.href = buildUrl(newPath);
|
||||
}else{
|
||||
// 如果包含,则先判断是不是当前模板的 url,如果不是 则替换成当前模板的 url
|
||||
if (firstSegment != strPcPath.replace('/', '')) {
|
||||
strCurrentPath = strCurrentPath.replace(firstSegment,strPcPath.replace('/', '')) ;
|
||||
window.location.href = buildUrl(strCurrentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,27 +100,38 @@ function handleRedirect() {
|
||||
|
||||
// 规范化路径名,将多个斜杠替换为单个斜杠
|
||||
const normalizedPath = pathname.replace(/\/+/g, '/');
|
||||
const strCurrentPath = normalizedPath || '/index.html';
|
||||
|
||||
var strCurrentPath = normalizedPath || '/index.html';
|
||||
const arrPcPathUrl = ['/pc', '/web', '/desktop', '/index', '/shouye', '/zhuomian', '/windows']; // 所有模板的 PC 目录
|
||||
// 构建URL,确保斜杠正确
|
||||
const buildUrl = (path) => {
|
||||
// 确保路径以单个斜杠开头,并移除多余斜杠
|
||||
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
|
||||
return `${origin}${cleanPath}${search}`;
|
||||
};
|
||||
|
||||
// 获取当前路径的第一个目录
|
||||
var firstSegment = strCurrentPath.split('/')[1] || '';
|
||||
|
||||
// 判断当前路径的第一个目录是否在其它模板的 PC 目录中
|
||||
const isInPcPathArray = arrPcPathUrl.some(pcPath => firstSegment.startsWith(pcPath.replace('/', '')));
|
||||
|
||||
if (isMobile()) {
|
||||
// 移动端逻辑:将PC路径重定向到移动端路径
|
||||
if (strCurrentPath.startsWith(strPcPath)) {
|
||||
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
|
||||
// 如果第一个目录 在pc 模板里面 则删除替换成空
|
||||
if (isInPcPathArray) {
|
||||
const newPath = strCurrentPath.replace(firstSegment, '');
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
|
||||
} else {
|
||||
// PC端逻辑:将非PC路径重定向到PC路径
|
||||
if (!strCurrentPath.startsWith(strPcPath)) {
|
||||
// 确保 PC 首页以斜杠结尾
|
||||
|
||||
if (!isInPcPathArray) {
|
||||
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
|
||||
window.location.href = buildUrl(newPath);
|
||||
}else{
|
||||
// 如果包含,则先判断是不是当前模板的 url,如果不是 则替换成当前模板的 url
|
||||
if (firstSegment != strPcPath.replace('/', '')) {
|
||||
strCurrentPath = strCurrentPath.replace(firstSegment,strPcPath.replace('/', '')) ;
|
||||
window.location.href = buildUrl(strCurrentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,27 +98,38 @@ function handleRedirect() {
|
||||
|
||||
// 规范化路径名,将多个斜杠替换为单个斜杠
|
||||
const normalizedPath = pathname.replace(/\/+/g, '/');
|
||||
const strCurrentPath = normalizedPath || '/index.html';
|
||||
|
||||
var strCurrentPath = normalizedPath || '/index.html';
|
||||
const arrPcPathUrl = ['/pc', '/web', '/desktop', '/index', '/shouye', '/zhuomian', '/windows']; // 所有模板的 PC 目录
|
||||
// 构建URL,确保斜杠正确
|
||||
const buildUrl = (path) => {
|
||||
// 确保路径以单个斜杠开头,并移除多余斜杠
|
||||
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
|
||||
return `${origin}${cleanPath}${search}`;
|
||||
};
|
||||
|
||||
// 获取当前路径的第一个目录
|
||||
var firstSegment = strCurrentPath.split('/')[1] || '';
|
||||
|
||||
// 判断当前路径的第一个目录是否在其它模板的 PC 目录中
|
||||
const isInPcPathArray = arrPcPathUrl.some(pcPath => firstSegment.startsWith(pcPath.replace('/', '')));
|
||||
|
||||
if (isMobile()) {
|
||||
// 移动端逻辑:将PC路径重定向到移动端路径
|
||||
if (strCurrentPath.startsWith(strPcPath)) {
|
||||
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
|
||||
// 如果第一个目录 在pc 模板里面 则删除替换成空
|
||||
if (isInPcPathArray) {
|
||||
const newPath = strCurrentPath.replace(firstSegment, '');
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
|
||||
} else {
|
||||
// PC端逻辑:将非PC路径重定向到PC路径
|
||||
if (!strCurrentPath.startsWith(strPcPath)) {
|
||||
// 确保 PC 首页以斜杠结尾
|
||||
|
||||
if (!isInPcPathArray) {
|
||||
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
|
||||
window.location.href = buildUrl(newPath);
|
||||
}else{
|
||||
// 如果包含,则先判断是不是当前模板的 url,如果不是 则替换成当前模板的 url
|
||||
if (firstSegment != strPcPath.replace('/', '')) {
|
||||
strCurrentPath = strCurrentPath.replace(firstSegment,strPcPath.replace('/', '')) ;
|
||||
window.location.href = buildUrl(strCurrentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,27 +98,38 @@ function handleRedirect() {
|
||||
|
||||
// 规范化路径名,将多个斜杠替换为单个斜杠
|
||||
const normalizedPath = pathname.replace(/\/+/g, '/');
|
||||
const strCurrentPath = normalizedPath || '/index.html';
|
||||
|
||||
var strCurrentPath = normalizedPath || '/index.html';
|
||||
const arrPcPathUrl = ['/pc', '/web', '/desktop', '/index', '/shouye', '/zhuomian', '/windows']; // 所有模板的 PC 目录
|
||||
// 构建URL,确保斜杠正确
|
||||
const buildUrl = (path) => {
|
||||
// 确保路径以单个斜杠开头,并移除多余斜杠
|
||||
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
|
||||
return `${origin}${cleanPath}${search}`;
|
||||
};
|
||||
|
||||
// 获取当前路径的第一个目录
|
||||
var firstSegment = strCurrentPath.split('/')[1] || '';
|
||||
|
||||
// 判断当前路径的第一个目录是否在其它模板的 PC 目录中
|
||||
const isInPcPathArray = arrPcPathUrl.some(pcPath => firstSegment.startsWith(pcPath.replace('/', '')));
|
||||
|
||||
if (isMobile()) {
|
||||
// 移动端逻辑:将PC路径重定向到移动端路径
|
||||
if (strCurrentPath.startsWith(strPcPath)) {
|
||||
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
|
||||
// 如果第一个目录 在pc 模板里面 则删除替换成空
|
||||
if (isInPcPathArray) {
|
||||
const newPath = strCurrentPath.replace(firstSegment, '');
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
|
||||
} else {
|
||||
// PC端逻辑:将非PC路径重定向到PC路径
|
||||
if (!strCurrentPath.startsWith(strPcPath)) {
|
||||
// 确保 PC 首页以斜杠结尾
|
||||
|
||||
if (!isInPcPathArray) {
|
||||
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
|
||||
window.location.href = buildUrl(newPath);
|
||||
}else{
|
||||
// 如果包含,则先判断是不是当前模板的 url,如果不是 则替换成当前模板的 url
|
||||
if (firstSegment != strPcPath.replace('/', '')) {
|
||||
strCurrentPath = strCurrentPath.replace(firstSegment,strPcPath.replace('/', '')) ;
|
||||
window.location.href = buildUrl(strCurrentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,27 +97,38 @@ function handleRedirect() {
|
||||
|
||||
// 规范化路径名,将多个斜杠替换为单个斜杠
|
||||
const normalizedPath = pathname.replace(/\/+/g, '/');
|
||||
const strCurrentPath = normalizedPath || '/index.html';
|
||||
|
||||
var strCurrentPath = normalizedPath || '/index.html';
|
||||
const arrPcPathUrl = ['/pc', '/web', '/desktop', '/index', '/shouye', '/zhuomian', '/windows']; // 所有模板的 PC 目录
|
||||
// 构建URL,确保斜杠正确
|
||||
const buildUrl = (path) => {
|
||||
// 确保路径以单个斜杠开头,并移除多余斜杠
|
||||
const cleanPath = `/${path.replace(/\/+/g, '/')}`.replace(/^\/+/, '/');
|
||||
return `${origin}${cleanPath}${search}`;
|
||||
};
|
||||
|
||||
// 获取当前路径的第一个目录
|
||||
var firstSegment = strCurrentPath.split('/')[1] || '';
|
||||
|
||||
// 判断当前路径的第一个目录是否在其它模板的 PC 目录中
|
||||
const isInPcPathArray = arrPcPathUrl.some(pcPath => firstSegment.startsWith(pcPath.replace('/', '')));
|
||||
|
||||
if (isMobile()) {
|
||||
// 移动端逻辑:将PC路径重定向到移动端路径
|
||||
if (strCurrentPath.startsWith(strPcPath)) {
|
||||
const newPath = strCurrentPath.replace(strPcPath, '') || '/';
|
||||
// 如果第一个目录 在pc 模板里面 则删除替换成空
|
||||
if (isInPcPathArray) {
|
||||
const newPath = strCurrentPath.replace(firstSegment, '');
|
||||
window.location.href = buildUrl(newPath);
|
||||
}
|
||||
|
||||
} else {
|
||||
// PC端逻辑:将非PC路径重定向到PC路径
|
||||
if (!strCurrentPath.startsWith(strPcPath)) {
|
||||
// 确保 PC 首页以斜杠结尾
|
||||
|
||||
if (!isInPcPathArray) {
|
||||
const newPath = strCurrentPath === '/' ? `${strPcPath}/` : `${strPcPath}${strCurrentPath}`;
|
||||
window.location.href = buildUrl(newPath);
|
||||
}else{
|
||||
// 如果包含,则先判断是不是当前模板的 url,如果不是 则替换成当前模板的 url
|
||||
if (firstSegment != strPcPath.replace('/', '')) {
|
||||
strCurrentPath = strCurrentPath.replace(firstSegment,strPcPath.replace('/', '')) ;
|
||||
window.location.href = buildUrl(strCurrentPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user