How to correctly solve the problem of resource error 404 in VuePress local access

  • 2021-10-11 17:36:52
  • OfStack

Background

Recently, I found that many small partners just used VuePress, and then accessed it directly with local browsers after 1build, resulting in black blocks. It's good to just have that problem, just install the vuepress-plugin-serve plug-in for the project.
But what if there is a need to view the documents generated by VuePress offline? So I specially studied 1-

Solution

Open the file. vuepress/config. js and change the value of base to./. For easy debugging, it is best to write this:


//base: "/",
base: "./",

Write two, one for Dev and one for Build.

Then open the file app. js under node_modules\ @ vuepress\ core\ lib\ client under the project and find the snippet below:


 const router = new Router({
 base: routerBase,
 mode: 'history',
 fallback: false,
 routes,
 scrollBehavior (to, from, savedPosition) {
  if (savedPosition) {
   return savedPosition
  } else if (to.hash) {
   if (Vue.$vuepress.$get('disableScrollBehavior')) {
    return false
   }
   return {
    selector: decodeURIComponent(to.hash)
   }
  } else {
   return { x: 0, y: 0 }
  }
 }
})

Just comment out mode: 'history' (let it default to hash mode).

In this way, you can happily Build project!


Related articles: