question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

fix: Error: use getRouteBaseName function from setup root context inside computed on server side

See original GitHub issue

🐛 The bug What isn’t working? Describe what the bug is.

On reload (server side): When you use the getRouteBaseName function from the setup root context inside a computed, an error is render : Cannot read property 'req' of undefined

By the way: $route from setup root context is not reactive. On update, watch and computed are not triggered

🛠️ To reproduce Steps to reproduce the behavior:

<template>
  <div>
    {{ routeBaseName }}
  </div>
</template>
<script lang="ts">
import { defineComponent, computed, useRoute } from '@nuxtjs/composition-api'

export default defineComponent({
    name: 'MyAccount',
    setup(_, { root: { getRouteBaseName } }) {
      const route = useRoute()

      const routeBaseName = computed(() => {
        return getRouteBaseName(route.value)
      })

      return {
        routeBaseName,
      }
    }
  })
</script>

🌈 Expected behaviour No error with request parameters, there is no need 😃

Informations

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
rchlcommented, Apr 4, 2021

I’d suggest:

import { useContext } from "@nuxtjs/composition-api";

export default defineComponent({
  setup(_) {
    const { getRouteBaseName } = useContext();
// ...

Also, you need to add nuxt-i18n to types array in tsconfig.json.

EDIT: In the end the goal is to provide a proper composition API but this should work for now, for this API at least.

1reaction
danielroecommented, Apr 2, 2021

@LouisMazel That’s likely something that can be addressed in the i18n module (which probably and understandably never foresaw access in this way). I’ll have a look.

cc @rchl

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I get rid of this error "Computed property validateState ...
So what this means is that computed properties are usually used to return a value based on the other values and we use...
Read more >
Explaining the Vue Context Argument - A Composition API ...
In this article, we'll be taking a look at the setup function's context argument. These changes are necessary because, in the Composition API, ......
Read more >
Vue i18n: Building a multi-language app with locale switcher
Vue i18n is a key process needed to localize your Vue apps and websites. Learn how to set up a Vue app with...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found