vuepress-reco / vuepress-theme-reco-1.x

🎨 This is the repo for vuepress-theme-reco 1.

Home Page:http://v1.vuepress-reco.recoluan.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

enhanceApp.js 解决中文路径问题出现 开发环境导航栏点击后直接跳转到生产环境页面

duktig666 opened this issue · comments

在你的仓库中的话可以 迭代一下

.vuepress/enhanceApp.js

export default (ctx) => {
  const routes = ctx.router.getRoutes()
  
  ctx.router.beforeEach((to, from, next) => {
    // 解决decode后反复重定向的问题
    const route = routes.find((v) => v.regex.test(to.path))

    // .html有重定向路由,无需特殊处理
    if (/\.html$/.test(to.path)) {
      return next()
    }

    // 不特殊处理 非通配符的 没有重定向的路由
    if (route && route.path !== '*' && !route.redirect) {
      return next()
    }

    // 解决中文标签/分类路由无法被正确加载的问题
    if (decodeURIComponent(to.path) !== to.path) {
      return next(
        Object.assign({}, to, {
          path: decodeURIComponent(to.path),
          fullPath: decodeURIComponent(to.fullPath)
        })
      )
    }

    next()
  })

  // 临时解决,防止内部调用钩子再处理
  ctx.router.beforeEach = () => {
    return
  }
}

经过测试已经成功解决了这个问题

Originally posted by @duktig666 in #395 (comment)

commented

不太清楚标题描述的问题,给个demo演示一下?

问题

开发环境点击中文路由
开发环境点击中文路由
点击中文路由跳转生产环境
点击中文路由跳转生产环境

控制台警告:
控制台警告

导航栏配置
导航栏配置

信息

版本:1.6.10
开发环境:win10
生产环境:github pages
仓库地址:https://github.com/duktig666/duktig666.github.io

不太清楚标题描述的问题,给个demo演示一下?
@ATQQ