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

vue-router 报错 Cannot read property '_normalized' of undefined #2

Open
Yoona6371 opened this issue Feb 28, 2020 · 2 comments
Open

Comments

@Yoona6371
Copy link

image

@Yoona6371
Copy link
Author

// 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)
})

})
}

@Yoona6371
Copy link
Author

router.push(context.url)
.catch(err => {
reject(err)
console.log('router push', err);
})

这一块报的错

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

1 participant