Skip to content
Discussion options

You must be logged in to vote

IMHO: preFetch isn't the right place for that, but if u wanna some piece of code to run only at the side side (or only at the client side), u can do that:

instead of

import { doSomethingOnServer } from 'server-only-package'
import { doSomethingOnClient } from 'client-only-package'

export default {
  async preFetch ({ ssrContext }) {
    if (ssrContext) {
      const res = await doSomethingOnServer()
    } else {
      const res = await doSomethingOnClient()
    }
  }
}

you would do:

export default {
  preFetch () {
    if (process.env.SERVER) {
      const { doSomethingOnServer } = require('server-only-package').default
      const res = await doSomethingOnServer ()
    }
    if (process.e…

Replies: 2 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@gustavotoyota
Comment options

@gustavotoyota
Comment options

Comment options

You must be logged in to vote
1 reply
@gustavotoyota
Comment options

Answer selected by gustavotoyota
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
2 participants