|
- /**
- * 将重构期间出现的不带 .html 的详情地址收敛到旧站已收录 URL。
- * 只做 URL 规范化,不参与任何页面业务逻辑。
- */
- export default defineNuxtRouteMiddleware((to) => {
- const path = to.path
- if (path.endsWith('.html')) return
-
- const needsHtmlSuffix = [
- /^\/pic\/[^/]+$/,
- /^\/info\/(?:new|course|what)\/[^/]+$/,
- /^\/info\/tag\/[^/]+$/,
- /^\/(?:news|baike|course)\/detail\/[^/]+$/,
- ].some(pattern => pattern.test(path))
-
- if (!needsHtmlSuffix) return
-
- return navigateTo(
- { path: `${path}.html`, query: to.query, hash: to.hash },
- { redirectCode: 301, replace: true },
- )
- })
|