We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
The text was updated successfully, but these errors were encountered:
// entry-server.js,它是暴露出一个函数,接受渲染上下文context参数(即server.js 中的content 变量), // 然后根据url匹配组件。所以说参数需要在我们调用renderToString传入context,并包括url属性。
import { createApp } from './app'
// export default context => { // const { app } = createApp() // return app // }
export default context => { // 因为有可能会是异步路由钩子函数或组件,所以我们将返回一个 Promise, // 以便服务器能够等待所有的内容在渲染前, // 就已经准备就绪。
return new Promise((resolve, reject) => { const { app, router } = createApp()
// 设置服务器端 router 的位置 router.push(context.url) .catch(err => { reject(err) console.log('router push', err); }) // 等到 router 将可能的异步组件和钩子函数解析完 router.onReady(() => { const matchedComponents = router.getMatchedComponents() // 匹配不到的路由,执行 reject 函数,并返回 404 if (!matchedComponents.length) { reject({ code: 404 }) return } // Promise 应该 resolve 应用程序实例,以便它可以渲染 resolve(app) }, err => { reject(err) })
}) }
Sorry, something went wrong.
router.push(context.url) .catch(err => { reject(err) console.log('router push', err); })
这一块报的错
No branches or pull requests
The text was updated successfully, but these errors were encountered: