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
- nuxt: 2.15.3
- @nuxtjs/composition-api: ^0.22.1
- Typescript
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (3 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I’d suggest:
Also, you need to add
nuxt-i18n
totypes
array intsconfig.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.
@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