Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

当使用enhanceApp.js并添加基本的代码后,无法渲染html文件 #2675

Closed
1 task
cmlanche opened this issue Oct 21, 2020 · 2 comments
Closed
1 task

Comments

@cmlanche
Copy link

System:
OS: macOS Mojave 10.14.6
CPU: (4) x64 Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
Binaries:
Node: 10.13.0 - /usr/local/bin/node
Yarn: 1.17.3 - /usr/local/bin/yarn
npm: 6.4.1 - /usr/local/bin/npm
Browsers:
Chrome: 86.0.4240.111
Edge: Not Found
Firefox: Not Found
Safari: 13.0.4
npmPackages:
@vuepress/core: 1.7.1
@vuepress/theme-default: 1.7.1
vuepress: ^1.7.1 => 1.7.1
npmGlobalPackages:
vuepress: Not Found

enhanceApp.js的内容如下:

export default ({
  Vue, // VuePress 正在使用的 Vue 构造函数
  options, // 附加到根实例的一些选项
  router, // 当前应用的路由实例
  siteData, // 站点元数据
  isServer // 当前应用配置是处于 服务端渲染 或 客户端
}) => {
  router.beforeEach((to, from, next) => {
  })
}

当删除enhanceApp.js文件或者里面不写任何代码,能够正常生成html

  • I confirm that this is an issue rather than a question.

Bug report

Steps to reproduce

What is expected?

能够正常将markdown文件渲染成html

What is actually happening?

assets的资源文件都生成了,比如css、img、js,一个HTML都没有生成,生成的日志中,没有出现success rendering html

Other relevant information

  • Output of npx vuepress info in my VuePress project:

rowboat-docs@1.0.0 docs:build /Users/chengming/Documents/好未来/轻舟/docs
vuepress build .

wait Extracting site metadata...
tip Apply theme @vuepress/theme-default ...
tip Apply plugin container (i.e. "vuepress-plugin-container") ...
tip Apply plugin @vuepress/register-components (i.e. "@vuepress/plugin-register-components") ...
tip Apply plugin @vuepress/active-header-links (i.e. "@vuepress/plugin-active-header-links") ...
tip Apply plugin @vuepress/search (i.e. "@vuepress/plugin-search") ...
tip Apply plugin @vuepress/nprogress (i.e. "@vuepress/plugin-nprogress") ...

✔ Client
Compiled successfully in 18.36s

✔ Server
Compiled successfully in 14.53s

wait Rendering static HTML...

@cmlanche
Copy link
Author

问题已解决,原因是如下代码不能ssr

router.beforeEach((to, from, next) => {
  })

需要做个判断:

if (isServer) {
router.beforeEach((to, from, next) => {
  })
}

@cnlydia
Copy link

cnlydia commented Mar 16, 2022

I think use below is correct
router.beforeEach((to, from, next) => {
//xxx
next()
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants