You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

23 line
645 B

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