Skip to content

Add head and body append to vue-ssr createApp #300

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

Merged
merged 1 commit into from
Feb 26, 2018

Conversation

marsimeau
Copy link
Contributor

It is currently impossible to append html to head or body tags using vue-ssr package's VueSSR.createApp. In order to allow packages such as vue-meta to work in SSR, I have made these changes:

  • Added the possibility of returning head and body strings (along with js and app) which will be appended to their respective tag.
  • Added the possibility of returning an appendHtml callback allowing to create head, body or js strings after the renderer as generated the app. This is required with vue-meta which only returns meta once the app as been rendered.

Here is an example of what would be possible with these changes:

VueSSR.createApp = function (context) {
  return new Promise((resolve, reject) => {
    const { app, router, store } = createApp()

    router.push(context.url)
    context.meta = app.$meta()

    // ...

    resolve({
      app,
      appendHtml() {
        const {
          title, link, style, script, noscript, meta
        } = context.meta.inject()

        return {
          head: `
            ${meta.text()}
            ${title.text()}
            ${link.text()}
            ${style.text()}
            ${script.text()}
            ${noscript.text()}
          `,
          body: script.text({ body: true })
        }
      }
    })
  })
}

Partially fixes #149. As far as I know, Meteor doesn't allow html or body attributes to be edited on the server.

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

Successfully merging this pull request may close these issues.

Support vue-meta on SSR
2 participants