N
Nuxt5mo ago
WiFi Plug

nuxt ui pro content navigation not showing up

<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const route = useRoute()

// Fetch the current page content
const { data: page } = await useAsyncData(route.path, () =>
queryCollection('content').path(route.path).first()
)
if (!page.value) {
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}

// Content navigation
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// Fetch the surrounding pages (prev/next)
const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
return queryCollectionItemSurroundings('content', route.path, {
fields: ['description'],
})
})
</script>

<template>
<UPage v-if="page" class="p-4">
<UPageHeader :title="page.title" :description="page.description" />

<template #left>
<UPageAside>
<UContentNavigation :navigation="navigation" highlight />
</UPageAside>
</template>

<UPageBody>
<ContentRenderer v-if="page.body" :value="page" />

<USeparator v-if="surround?.filter(Boolean).length" />

<!-- Prev/Next navigation -->
<UContentSurround :surround="(surround as any)" />
</UPageBody>

<!-- Table of Contents in the right slot -->
<template v-if="page?.body?.toc?.links?.length" #right>
<UContentToc
highlight
highlight-color="primary"
color="primary"
:links="page?.body?.toc?.links"
/>
</template>
</UPage>
</template>
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const route = useRoute()

// Fetch the current page content
const { data: page } = await useAsyncData(route.path, () =>
queryCollection('content').path(route.path).first()
)
if (!page.value) {
throw createError({ statusCode: 404, statusMessage: 'Page not found', fatal: true })
}

// Content navigation
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// Fetch the surrounding pages (prev/next)
const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
return queryCollectionItemSurroundings('content', route.path, {
fields: ['description'],
})
})
</script>

<template>
<UPage v-if="page" class="p-4">
<UPageHeader :title="page.title" :description="page.description" />

<template #left>
<UPageAside>
<UContentNavigation :navigation="navigation" highlight />
</UPageAside>
</template>

<UPageBody>
<ContentRenderer v-if="page.body" :value="page" />

<USeparator v-if="surround?.filter(Boolean).length" />

<!-- Prev/Next navigation -->
<UContentSurround :surround="(surround as any)" />
</UPageBody>

<!-- Table of Contents in the right slot -->
<template v-if="page?.body?.toc?.links?.length" #right>
<UContentToc
highlight
highlight-color="primary"
color="primary"
:links="page?.body?.toc?.links"
/>
</template>
</UPage>
</template>
hi im trying to setup a content page with navigation on the left but i don't see the content navigation. do i need to set anything up in another file for it?
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
collections: {
content: defineCollection({
type: 'page',
source: '**/*.md',
}),
},
})
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
collections: {
content: defineCollection({
type: 'page',
source: '**/*.md',
}),
},
})
128 Replies
kapa.ai
kapa.ai5mo ago
Hi @WiFi Plug. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To display the content navigation with <UContentNavigation :navigation="navigation" />, you need to ensure that the navigation data is actually being provided and injected. In your code, you are using:
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
However, for this to work, the navigation value must be provided higher up in your app, typically in your layout or app.vue. This is not handled automatically by Nuxt Content or Nuxt UI Pro—you need to fetch the navigation tree (using queryCollectionNavigation) and provide it via Vue's provide/inject mechanism. What you need to do: 1. Fetch the navigation tree in your layout or app.vue using queryCollectionNavigation:
// app.vue or your layout file
<script setup lang="ts">
import { provide } from 'vue'
import { queryCollectionNavigation } from '#content/utils'

const { data: navigation } = await useAsyncData('navigation', () =>
queryCollectionNavigation('content')
)

provide('navigation', navigation)
</script>
// app.vue or your layout file
<script setup lang="ts">
import { provide } from 'vue'
import { queryCollectionNavigation } from '#content/utils'

const { data: navigation } = await useAsyncData('navigation', () =>
queryCollectionNavigation('content')
)

provide('navigation', navigation)
</script>
2. Now, your page can inject the navigation as you are already doing:
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')
3. Make sure you are using the correct collection name in queryCollectionNavigation.
If your collection is named content in your content.config.ts, then queryCollectionNavigation('content') is correct. Summary:
The navigation data must be provided using Vue's provide/inject. If you skip this step, navigation will be undefined and nothing will show up in <UContentNavigation>. This is a common setup pattern shown in the official docs and migration guides for Nuxt Content x UI Pro v3 How to upgrade your Nuxt documentation website to Content x UI v3 and ContentNavigation usage. If you follow these steps and still don't see the navigation, double-check that your content files are in the correct directory and that your collection is set up properly in content.config.ts. --- References: - ContentNavigation usage - Migration guide: Migrate docs page - queryCollectionNavigation utility ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai can i define it within the slug file directly? as this is navigation only for my legal pages won't be reused by others
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You can define and use navigation data directly within your [...slug].vue file by fetching it with queryCollectionNavigation for your specific collection or directory. This approach is suitable if the navigation is only relevant to a subset of pages (like your legal pages) and you don't want to provide it globally. Here’s how you can do it:
<script setup lang="ts">
const { data: navigation } = await useAsyncData('legal-navigation', () =>
queryCollectionNavigation('content')
.where('category', '=', 'legal') // Optional: filter for legal pages if you use a category field
)
</script>

<template>
<UPage>
<template #left>
<UPageAside>
<UContentNavigation :navigation="navigation" highlight />
</UPageAside>
</template>
<!-- ...rest of your template -->
</UPage>
</template>
<script setup lang="ts">
const { data: navigation } = await useAsyncData('legal-navigation', () =>
queryCollectionNavigation('content')
.where('category', '=', 'legal') // Optional: filter for legal pages if you use a category field
)
</script>

<template>
<UPage>
<template #left>
<UPageAside>
<UContentNavigation :navigation="navigation" highlight />
</UPageAside>
</template>
<!-- ...rest of your template -->
</UPage>
</template>
- You do not need to use provide/inject if you are only using the navigation in this file. - Just fetch the navigation tree with queryCollectionNavigation and pass it directly to <UContentNavigation /> as shown above. Note:
If you want to filter only legal pages, you can use .where() as shown, but you need to have a field (like category: 'legal') in your content files to filter by. Otherwise, you can fetch all navigation items for the relevant directory. This approach is supported and shown in the queryCollectionNavigation documentation, where navigation is fetched and used directly in a page component without global injection. If you need more advanced filtering or structure, you can adjust the query accordingly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so in my content folder i have a folder for blog a folder for support and in the root i have privacy-policy.md, terms-of-service and site-rules.md so how do i define 3 collections for these different items?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To define three separate collections for your different content types (blog, support, and legal pages like privacy-policy, terms-of-service, and site-rules), you can configure your content.config.ts like this:
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
collections: {
blog: defineCollection({
type: 'page',
source: 'blog/*.md'
}),
support: defineCollection({
type: 'page',
source: 'support/*.md'
}),
legal: defineCollection({
type: 'page',
source: '{privacy-policy,terms-of-service,site-rules}.md'
})
}
})
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
collections: {
blog: defineCollection({
type: 'page',
source: 'blog/*.md'
}),
support: defineCollection({
type: 'page',
source: 'support/*.md'
}),
legal: defineCollection({
type: 'page',
source: '{privacy-policy,terms-of-service,site-rules}.md'
})
}
})
- The blog collection includes all Markdown files in the content/blog/ directory. - The support collection includes all Markdown files in the content/support/ directory. - The legal collection includes the three specific Markdown files in the root of your content/ directory. This setup uses the source property with glob patterns to target the correct files for each collection. You can then query each collection separately in your app as needed see: Collection Sources see: Defining Collections. If you want to further customize schemas or add validation, you can add a schema property to each collection as shown in the documentation. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai if i want to have those overarching categories and icon shown then do i need to create my navigation list manually like this?
const navigation = ref([
{
title: 'Guide',
icon: 'i-lucide-book-open',
path: '#getting-started',
children: [
{
title: 'Introduction',
path: '#introduction',
active: true
},
{
title: 'Installation',
path: '#installation'
}
]
},
{
title: 'Composables',
icon: 'i-lucide-database',
path: '#composables',
children: [
{
title: 'defineShortcuts',
path: '#defineshortcuts'
},
{
title: 'useModal',
path: '#usemodal'
}
]
}
])
const navigation = ref([
{
title: 'Guide',
icon: 'i-lucide-book-open',
path: '#getting-started',
children: [
{
title: 'Introduction',
path: '#introduction',
active: true
},
{
title: 'Installation',
path: '#installation'
}
]
},
{
title: 'Composables',
icon: 'i-lucide-database',
path: '#composables',
children: [
{
title: 'defineShortcuts',
path: '#defineshortcuts'
},
{
title: 'useModal',
path: '#usemodal'
}
]
}
])
or can it be semi automated where the children are automatically generated but i just create the main category and icon?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You do not have to create the entire navigation list manually. You can semi-automate this process by using the .navigation.yml file in each directory to define metadata such as the title and icon for each category. The children (pages within each directory) will be generated automatically by queryCollectionNavigation. For example, in your content/blog/ folder, you can add a .navigation.yml file:
title: Blog
icon: i-lucide-book-open
title: Blog
icon: i-lucide-book-open
Do the same for content/support/ and for your legal pages, you can create a virtual folder (e.g., content/legal/), move your legal markdown files there, and add a .navigation.yml:
title: Legal
icon: i-lucide-shield
title: Legal
icon: i-lucide-shield
Then, when you use queryCollectionNavigation, it will generate a navigation tree with your custom titles and icons for each category, and automatically include the children (the pages inside each folder) see: Navigation metadata with .navigation.yml. Summary:
- Add a .navigation.yml file in each folder to set the category title and icon. - Children are generated automatically. - No need to manually build the full navigation array. If you keep your legal pages in the root and want them grouped, you would need to either move them into a folder or manually construct the navigation for that group, as .navigation.yml works at the directory level. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so i moved my legal pages to content/legal/ but i want them served at the root of my site so how can i do that
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To serve your legal pages (now located in content/legal/) at the root of your site (e.g., /privacy-policy instead of /legal/privacy-policy), you can use the prefix option in your collection definition within content.config.ts. Set prefix: '/' for your legal collection. This tells Nuxt Content to generate the routes at the root level, even though the files are in a subfolder. Here’s how you can configure it:
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
collections: {
legal: defineCollection({
type: 'page',
source: {
include: 'legal/*.md',
prefix: '/'
}
}),
// ... other collections
}
})
import { defineContentConfig, defineCollection } from '@nuxt/content'

export default defineContentConfig({
collections: {
legal: defineCollection({
type: 'page',
source: {
include: 'legal/*.md',
prefix: '/'
}
}),
// ... other collections
}
})
With this setup, files like content/legal/privacy-policy.md will be available at /privacy-policy on your site, not /legal/privacy-policy see: Collection Sources - prefix. This approach allows you to organize your files in a subfolder for clarity, while still serving them at the root URL paths. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so i did that and my legal pages correctly show at the root of my site however the .navigation.yml isn't displaying the category in the navbar
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- When you use the prefix: '/' option to serve your legal pages at the root, Nuxt Content will generate the routes at the root level, but the .navigation.yml file in the legal/ directory will not create a visible "Legal" category in the navigation tree. This is because the navigation grouping is based on the directory structure as it appears in the URL structure. When you flatten the URLs to the root, the grouping is lost, and the metadata from .navigation.yml is not shown as a category in the navigation bar see: Navigation metadata with .navigation.yml. Summary:
- If you use prefix: '/', the children (legal pages) appear at the root, and the parent directory's .navigation.yml does not create a group/category in the navigation. - This is the expected behavior according to the current Nuxt Content documentation. If you want a "Legal" category to appear in your navigation, you would need to either: - Not use prefix: '/' (so the pages are grouped under /legal), or - Manually construct your navigation tree for this section, as automatic grouping by directory is not possible when the URLs are flattened to the root. I'm sorry, but there's no information in the knowledge sources about a built-in way to both flatten the URLs and retain the parent directory as a navigation group using .navigation.yml. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai
<script setup lang="ts">
const route = useRoute()

const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
return queryCollectionItemSurroundings('content', route.path, {
fields: ['description']
})
})
</script>

<template>
<UContentSurround :surround="(surround as any)" />
</template>
<script setup lang="ts">
const route = useRoute()

const { data: surround } = await useAsyncData(`${route.path}-surround`, () => {
return queryCollectionItemSurroundings('content', route.path, {
fields: ['description']
})
})
</script>

<template>
<UContentSurround :surround="(surround as any)" />
</template>
can i modify my content surround as i have only 3 legal pages so i always want to show links to the other two pages rather than the page that's before or after this one. can i manually set this behaviour? maybe where it quieries for pages minus the current open one then displays those two?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The knowledge sources do not explicitly mention a built-in way to customize <UContentSurround> to always show links to the other two legal pages, regardless of order, using the standard queryCollectionItemSurroundings utility. By default, queryCollectionItemSurroundings is designed to show the previous and next items relative to the current page, not all other items in the collection queryCollectionItemSurroundings usage. However, you can manually construct the surround array and pass it to <UContentSurround>. The component accepts a surround prop, which is simply an array of links. You can fetch all legal pages, filter out the current one, and pass the remaining two as the surround links. Here’s an example of how you might do this:
<script setup lang="ts">
const route = useRoute()

// Fetch all legal pages
const { data: legalPages } = await useAsyncData('legal-pages', () =>
queryCollection('legal').find()
)

// Filter out the current page
const surround = computed(() =>
(legalPages.value || [])
.filter(page => page._path !== route.path)
.map(page => ({
title: page.title,
path: page._path,
description: page.description
}))
)
</script>

<template>
<UContentSurround :surround="surround" />
</template>
<script setup lang="ts">
const route = useRoute()

// Fetch all legal pages
const { data: legalPages } = await useAsyncData('legal-pages', () =>
queryCollection('legal').find()
)

// Filter out the current page
const surround = computed(() =>
(legalPages.value || [])
.filter(page => page._path !== route.path)
.map(page => ({
title: page.title,
path: page._path,
description: page.description
}))
)
</script>

<template>
<UContentSurround :surround="surround" />
</template>
This approach is supported by the API of <UContentSurround>, which allows you to pass any array of links as the surround prop UContentSurround usage. In summary:
You can manually set the surround prop to always show the other two legal pages by constructing the array yourself, as shown above. There is no built-in utility for this exact behavior, but the component supports manual data. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai and how do i add navigation to the upageheader with content? i tried yesterday but failed to make it work
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To add navigation to the <UPageHeader> using content from your Nuxt Content collection, you can use the links prop. This prop expects an array of link objects (with properties like label, icon, to, etc.), which you can generate from your content or define manually. Example:
<script setup lang="ts">
const links = ref([
{
label: 'Privacy Policy',
icon: 'i-lucide-shield',
to: '/privacy-policy'
},
{
label: 'Terms of Service',
icon: 'i-lucide-file-text',
to: '/terms-of-service'
},
{
label: 'Site Rules',
icon: 'i-lucide-gavel',
to: '/site-rules'
}
])
</script>

<template>
<UPageHeader
title="Legal"
description="Our legal documents and policies."
:links="links"
/>
</template>
<script setup lang="ts">
const links = ref([
{
label: 'Privacy Policy',
icon: 'i-lucide-shield',
to: '/privacy-policy'
},
{
label: 'Terms of Service',
icon: 'i-lucide-file-text',
to: '/terms-of-service'
},
{
label: 'Site Rules',
icon: 'i-lucide-gavel',
to: '/site-rules'
}
])
</script>

<template>
<UPageHeader
title="Legal"
description="Our legal documents and policies."
:links="links"
/>
</template>
If you want to generate the links dynamically from your content collection, you can fetch the pages and map them to the required format:
<script setup lang="ts">
const { data: legalPages } = await useAsyncData('legal-pages', () =>
queryCollection('legal').find()
)

const links = computed(() =>
(legalPages.value || []).map(page => ({
label: page.title,
to: page._path
// Add icon or other properties if available in your content
}))
)
</script>

<template>
<UPageHeader
title="Legal"
description="Our legal documents and policies."
:links="links"
/>
</template>
<script setup lang="ts">
const { data: legalPages } = await useAsyncData('legal-pages', () =>
queryCollection('legal').find()
)

const links = computed(() =>
(legalPages.value || []).map(page => ({
label: page.title,
to: page._path
// Add icon or other properties if available in your content
}))
)
</script>

<template>
<UPageHeader
title="Legal"
description="Our legal documents and policies."
:links="links"
/>
</template>
This approach is documented in the UPageHeader usage guide, which shows how to use the links prop to display navigation buttons in the header. If you want to display more complex navigation (like a breadcrumb), you can use the headline slot or prop, as described in the typography and breadcrumb documentation. References: - UPageHeader links prop - Dynamic links example - Breadcrumb/headline example ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai sorry i meant the breadcrumbs
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To add breadcrumbs to the <UPageHeader> using your content, you should use the headline slot of <UPageHeader> and render a <UBreadcrumb> component inside it. The recommended approach is to use the findPageBreadcrumb and mapContentNavigation utilities to generate the breadcrumb items from your content navigation. Here’s how you can do it, based on the official documentation:
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const route = useRoute()
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// Fetch the current page content
const { data: page } = await useAsyncData(route.path, () =>
queryCollection('content').path(route.path).first()
)

// Generate the breadcrumb items
const breadcrumb = computed(() =>
mapContentNavigation(findPageBreadcrumb(navigation?.value, page.value)).map(({ icon, ...link }) => link)
)
</script>

<template>
<UPage>
<UPageHeader v-bind="page">
<template #headline>
<UBreadcrumb :items="breadcrumb" />
</template>
</UPageHeader>
</UPage>
</template>
<script setup lang="ts">
import type { ContentNavigationItem } from '@nuxt/content'

const route = useRoute()
const navigation = inject<Ref<ContentNavigationItem[]>>('navigation')

// Fetch the current page content
const { data: page } = await useAsyncData(route.path, () =>
queryCollection('content').path(route.path).first()
)

// Generate the breadcrumb items
const breadcrumb = computed(() =>
mapContentNavigation(findPageBreadcrumb(navigation?.value, page.value)).map(({ icon, ...link }) => link)
)
</script>

<template>
<UPage>
<UPageHeader v-bind="page">
<template #headline>
<UBreadcrumb :items="breadcrumb" />
</template>
</UPageHeader>
</UPage>
</template>
Key points: - findPageBreadcrumb recursively finds the breadcrumb path for the current page. - mapContentNavigation transforms the navigation data into the format expected by <UBreadcrumb>. - You need to provide the navigation data (see previous answers for how to provide/inject it). This is the officially documented way to add breadcrumbs to your page header using Nuxt Content and Nuxt UI Pro see: Typography utils and breadcrumb example. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kap Cannot find name 'mapContentNavigation'.ts-plugin(2304) @kapa.ai Cannot find name 'mapContentNavigation'.ts-plugin(2304)
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The error Cannot find name 'mapContentNavigation' occurs because mapContentNavigation is an auto-imported utility provided by Nuxt UI Pro when using Nuxt Content v3, but it may not be available if your setup is missing the correct module versions or if auto-imports are not working as expected. According to the official documentation, mapContentNavigation should be auto-imported and available for use in your components when you have both @nuxt/content and @nuxt/ui-pro properly installed and configured in your nuxt.config.ts file, with @nuxt/ui-pro listed before @nuxt/content in the modules array see: Typography utils. Checklist: 1. Check your nuxt.config.ts:
export default defineNuxtConfig({
modules: [
'@nuxt/ui-pro',
'@nuxt/content'
],
// ...other config
})

export default defineNuxtConfig({
modules: [
'@nuxt/ui-pro',
'@nuxt/content'
],
// ...other config
})

The order is important: @nuxt/ui-pro must come before @nuxt/content. 2. No need to import manually:
If your setup is correct, you should be able to use mapContentNavigation directly in your <script setup> without importing it. 3. If the error persists:
- Make sure you are using compatible versions: Nuxt UI Pro v3 with Nuxt Content v3 see: Getting started with content. - Restart your dev server after making changes to your configuration. If after checking these points you still get the error, it may indicate an issue with your project setup or a problem with auto-imports. The knowledge sources do not provide a manual import path for mapContentNavigation, so if auto-imports are not working, you may need to review your module installation or consult the official documentation for troubleshooting. Summary:
mapContentNavigation should be available as an auto-imported utility if your modules are set up correctly. Double-check your configuration and module versions as described above see: Typography utils. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai can i manually construct the breadcrumbs as i think they're not displaying because the legal pages are in content/legal/privacy-policy.md but then are rendered at the root of my site. but i want the breadcrumbs to have a link to home and the currently opened page so maybe manual is better in that case
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can manually construct the breadcrumbs for your legal pages. If your legal pages are stored in content/legal/ but are rendered at the root (e.g., /privacy-policy), the automatic breadcrumb utilities may not generate the desired breadcrumb structure. In this case, creating a manual breadcrumb array is a practical solution. Here’s how you can do it:
<script setup lang="ts">
import { useRoute } from 'vue-router'

const route = useRoute()

const breadcrumbs = computed(() => [
{ label: 'Home', to: '/' },
{ label: getPageTitle(route.path), to: route.path }
])

function getPageTitle(path) {
// Map your routes to titles
switch (path) {
case '/privacy-policy':
return 'Privacy Policy'
case '/terms-of-service':
return 'Terms of Service'
case '/site-rules':
return 'Site Rules'
default:
return ''
}
}
</script>

<template>
<UBreadcrumb :items="breadcrumbs" />
</template>
<script setup lang="ts">
import { useRoute } from 'vue-router'

const route = useRoute()

const breadcrumbs = computed(() => [
{ label: 'Home', to: '/' },
{ label: getPageTitle(route.path), to: route.path }
])

function getPageTitle(path) {
// Map your routes to titles
switch (path) {
case '/privacy-policy':
return 'Privacy Policy'
case '/terms-of-service':
return 'Terms of Service'
case '/site-rules':
return 'Site Rules'
default:
return ''
}
}
</script>

<template>
<UBreadcrumb :items="breadcrumbs" />
</template>
This approach gives you full control over the breadcrumb structure and ensures that the breadcrumb always shows "Home" and the current page, regardless of the file structure or routing setup. The knowledge sources confirm that <UBreadcrumb> accepts a manual array of items with label and to properties, and you can use it independently of the automatic navigation utilities see: UBreadcrumb usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai how do i handle seo on these pages?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To handle SEO on your legal pages in Nuxt, you should use the useSeoMeta composable within each page component. This allows you to set meta tags such as title, description, ogTitle, and others, which are important for search engines and social sharing. Example for a legal page:
<script setup lang="ts">
useSeoMeta({
title: 'Privacy Policy',
description: 'Read our privacy policy to learn how we handle your data.',
ogTitle: 'Privacy Policy',
ogDescription: 'Read our privacy policy to learn how we handle your data.',
// You can add more tags as needed, such as ogImage, twitterCard, etc.
})
</script>
<script setup lang="ts">
useSeoMeta({
title: 'Privacy Policy',
description: 'Read our privacy policy to learn how we handle your data.',
ogTitle: 'Privacy Policy',
ogDescription: 'Read our privacy policy to learn how we handle your data.',
// You can add more tags as needed, such as ogImage, twitterCard, etc.
})
</script>
You can also use dynamic or computed values if needed. If your SEO data is stored in your content files (e.g., in a seo field), you can populate useSeoMeta with those values:
<script setup lang="ts">
const { data: page } = await useAsyncData('privacy-policy', () =>
queryCollection('legal').path('/privacy-policy').first()
)

useSeoMeta({
title: page.value?.seo?.title || page.value?.title,
description: page.value?.seo?.description || page.value?.description,
ogTitle: page.value?.seo?.title || page.value?.title,
ogDescription: page.value?.seo?.description || page.value?.description,
})
</script>
<script setup lang="ts">
const { data: page } = await useAsyncData('privacy-policy', () =>
queryCollection('legal').path('/privacy-policy').first()
)

useSeoMeta({
title: page.value?.seo?.title || page.value?.title,
description: page.value?.seo?.description || page.value?.description,
ogTitle: page.value?.seo?.title || page.value?.title,
ogDescription: page.value?.seo?.description || page.value?.description,
})
</script>
This approach is recommended in the Nuxt documentation for SEO and meta management SEO and Meta, and is also shown in Nuxt Content migration guides Content x UI v3 migration. Summary:
- Use useSeoMeta in each legal page to set SEO meta tags. - You can hardcode values or use data from your content files. - This ensures each page has the correct SEO metadata for search engines and social sharing. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai i want the seo title to change to be like "Privacy Policy - AppName" where the first part changes based on the page title
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You can achieve dynamic SEO titles like "Privacy Policy - AppName" by using a computed value or a function in the useSeoMeta composable. According to the Nuxt documentation, useSeoMeta supports reactive values and functions for its fields useSeoMeta usage. Example:
<script setup lang="ts">
const appName = 'AppName'
const pageTitle = 'Privacy Policy' // Replace with your dynamic title source

useSeoMeta({
title: () => `${pageTitle} - ${appName}`,
ogTitle: () => `${pageTitle} - ${appName}`,
// ...other meta fields
})
</script>
<script setup lang="ts">
const appName = 'AppName'
const pageTitle = 'Privacy Policy' // Replace with your dynamic title source

useSeoMeta({
title: () => `${pageTitle} - ${appName}`,
ogTitle: () => `${pageTitle} - ${appName}`,
// ...other meta fields
})
</script>
If your page title comes from your content file, you can use a ref or computed property:
<script setup lang="ts">
const appName = 'AppName'
const { data: page } = await useAsyncData('privacy-policy', () =>
queryCollection('legal').path('/privacy-policy').first()
)

useSeoMeta({
title: () => `${page.value?.title} - ${appName}`,
ogTitle: () => `${page.value?.title} - ${appName}`,
// ...other meta fields
})
</script>
<script setup lang="ts">
const appName = 'AppName'
const { data: page } = await useAsyncData('privacy-policy', () =>
queryCollection('legal').path('/privacy-policy').first()
)

useSeoMeta({
title: () => `${page.value?.title} - ${appName}`,
ogTitle: () => `${page.value?.title} - ${appName}`,
// ...other meta fields
})
</script>
This approach is fully supported and recommended for dynamic SEO meta tags in Nuxt see: useSeoMeta reactivity. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai how do i set my site to only be available in dark mode?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To set your Nuxt site to only be available in dark mode, you can force dark mode by configuring the color mode in your Nuxt app. According to the official Nuxt UI documentation, you can do this by setting the colorMode property in your nuxt.config.ts or by using definePageMeta in your page components. Recommended approach (global, for the whole site): In your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark', // Set default preference to dark
fallback: 'dark', // Fallback to dark if no preference is found
// You can also add 'forced: true' if you want to prevent switching
}
}
})
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark', // Set default preference to dark
fallback: 'dark', // Fallback to dark if no preference is found
// You can also add 'forced: true' if you want to prevent switching
}
}
})
Or, to force dark mode and prevent users from switching:
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark',
fallback: 'dark',
forced: true
}
}
})
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark',
fallback: 'dark',
forced: true
}
}
})
Alternatively, you can force dark mode on a per-page basis using definePageMeta:
<script setup lang="ts">
definePageMeta({
colorMode: 'dark'
})
</script>
<script setup lang="ts">
definePageMeta({
colorMode: 'dark'
})
</script>
Note:
If you use the forced: true option, users will not be able to switch to light mode, and your site will always render in dark mode see: Nuxt UI Color Mode. --- Important:
If a user has a color mode preference saved in their browser's localStorage, it may override your default unless you use the forced: true option see: Stack Overflow discussion. --- References are integrated above as per your instructions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai hmm that didn't work i tried this code
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark',
fallback: 'dark',
forced: true
}
}
})
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark',
fallback: 'dark',
forced: true
}
}
})
but still light mode is shown. and i used forced: true i tried opening the site in incognito incase it's some cashed issue but same thing
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- I'm sorry you're still seeing light mode even after setting forced: true in your nuxt.config.ts. According to the official Nuxt UI documentation, setting:
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark',
fallback: 'dark',
forced: true
}
}
})
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark',
fallback: 'dark',
forced: true
}
}
})
should force your site to always use dark mode and prevent switching Nuxt UI Color Mode. If this is not working: - Double-check that you are using the latest versions of @nuxt/ui and @nuxtjs/color-mode, as the integration relies on these modules. - Ensure that you do not have any other color mode configuration elsewhere (such as in app.config.ts or vite.config.ts) that could override this setting. - The knowledge sources do not mention any additional required steps or known issues with this configuration. If the problem persists, the knowledge sources do not provide further troubleshooting steps for this specific issue. It may be a bug or a version mismatch. In that case, you may want to check for open issues on the Nuxt UI GitHub or Nuxt Color Mode GitHub repositories. Summary:
The configuration you used is correct according to the documentation, and it should force dark mode. If it does not, the knowledge sources do not provide more information on resolving this issue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai well this code succesfully disables color mode right ui: { colorMode: false, }, but then it's just defaulting to light mode so how do i change that default?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Disabling color mode with ui: { colorMode: false } in your nuxt.config.ts will turn off the color mode integration, and your site will use the default theme (which is light mode by default). The knowledge sources do not provide a documented way to set the default to dark mode when color mode is disabled. The default styling will be light unless you manually override your styles (for example, by customizing your Tailwind CSS config or global CSS), but this is not covered in the official Nuxt UI documentation. Summary:
- Setting colorMode: false disables color mode and defaults to light mode. - The knowledge sources do not describe a built-in way to make dark mode the default when color mode is disabled Nuxt UI Installation Options. If you want your site to default to dark mode, you should use the color mode integration and set the preference to dark, rather than disabling it. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
// Force dark mode on site const colorMode = useColorMode() colorMode.preference = 'dark' i also tried this code in my app.vue script but that also doesn't work? @kapa.ai
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Setting colorMode.preference = 'dark' in your app.vue script does not guarantee that your site will always be in dark mode. According to the knowledge sources, this approach only works if the color mode is not forced elsewhere and if there is no conflicting value in localStorage. The @nuxtjs/color-mode module will prioritize the value in localStorage over your code, so if a user has previously selected a mode, that will take precedence Stack Overflow discussion. Additionally, the knowledge sources clarify that definePageMeta({ colorMode: 'dark' }) only works in .vue files within the /pages directory, not in app.vue Stack Overflow discussion. Summary:
- Setting colorMode.preference = 'dark' in app.vue does not reliably force dark mode. - The value in localStorage will override your setting. - Forcing dark mode globally should be done via the Nuxt UI color mode configuration, but if that is not working, the knowledge sources do not provide an alternative guaranteed method. If the documented configuration options are not working, the knowledge sources do not provide further troubleshooting steps or alternative solutions. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
"// Locale i18n stuff for language setup automatically import * as locales from '@nuxt/ui/locale' const { locale } = useI18n() const lang = computed(() => locales[locale.value].code) const dir = computed(() => locales[locale.value].dir) useHead({ htmlAttrs: { lang, dir, }, @kapa.ai i tried to setup i18n with nuxt ui. i put that in my app.vue and this in my nuxt config " i18n: { strategy: 'prefix_except_default', defaultLocale: 'en', detectBrowserLanguage: { useCookie: true, cookieKey: 'i18n_redirected', fallbackLocale: 'en', redirectOn: 'root', // only redirect when visiting root }, locales: [ { code: 'en', name: 'English', }, { code: 'fr', name: 'Français', }, { code: 'es', name: 'Español', }, ], lazy: true, },' but im not sure it's working?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on your setup, you are combining Nuxt UI's locale utilities with Nuxt I18n configuration. This is a valid approach, and your code for setting the lang and dir attributes on the <html> element using useHead is correct and follows the official Nuxt UI documentation:
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
const lang = computed(() => locales[locale.value].code)
const dir = computed(() => locales[locale.value].dir)

useHead({
htmlAttrs: {
lang,
dir,
}
})
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
const lang = computed(() => locales[locale.value].code)
const dir = computed(() => locales[locale.value].dir)

useHead({
htmlAttrs: {
lang,
dir,
}
})
Dynamic direction example Your nuxt.config.ts i18n configuration also matches the recommended structure for Nuxt I18n, including browser language detection and lazy loading:
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}
Nuxt UI I18n usage How to check if it's working: - When you visit your site, the <html> tag should have the correct lang and dir attributes based on the current locale. - Changing the language (e.g., via a language switcher using setLocale) should update these attributes and the displayed content. - The URL should reflect the locale according to your strategy (e.g., /fr/ for French, except for the default locale). If you are not seeing the expected behavior: - Make sure your language files or messages are correctly set up and loaded (especially if using lazy: true). - Ensure you are using the correct versions of Nuxt, Nuxt UI, and Nuxt I18n, as mismatches can cause issues. - If you have issues with browser language detection, double-check your configuration and refer to the Nuxt I18n documentation. If you need to debug further, you can add logging or use the browser dev tools to inspect the <html> attributes and check the current locale. In summary:
Your setup matches the official documentation, and if the lang and dir attributes are updating as you change languages, then it is working as intended. If not, check your language files and module versions for compatibility. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so i still need to setup the files for each language manually in an i18n folder or not as i thought nuxt ui had some pre made i can use?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Nuxt UI provides a set of pre-made locale objects (such as en, fr, es, etc.) that you can use for UI components, but these are only for Nuxt UI’s own component translations (like button labels, navigation, etc.), not for your app’s content or custom translation strings. For your application’s actual content and custom translations, you still need to set up your own language files (e.g., in an i18n or locales folder) and configure them in your Nuxt I18n setup. The Nuxt UI locales are helpful for UI elements, but they do not replace the need for your own translation files for your app’s text and content see: Nuxt UI I18n usage and Supported languages. Summary:
- Nuxt UI locales: For UI component translations only. - Your own language files: Still required for your app’s content and custom translations. If you want to use the pre-made Nuxt UI locales for your UI, you can import them from @nuxt/ui/locale. For your own content, you must provide your own translation files. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so with my setup the deafult text in buttons etc should be translated though right?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, with your setup—using Nuxt UI and importing the appropriate locale from @nuxt/ui/locale—the default text in Nuxt UI components (such as buttons, navigation, etc.) should be automatically translated according to the selected locale. This is confirmed in the Nuxt UI documentation, which states that you can use the pre-made locales for UI components, and the translations will be applied to the default text of those components Supported languages. However, this only applies to the default UI text provided by Nuxt UI components. Any custom text or content in your application will still require your own translation files and setup. So, as long as you are correctly passing the locale to <UApp :locale="locales[locale]" /> and have set up your i18n integration as described, the default UI component text will be translated automatically Nuxt UI I18n usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai ok so if i want a language picker in my footer then i have
// lang stuff delete later
import * as locales from '@nuxt/ui/locale'

const { locale } = useI18n()
// lang stuff delete later
import * as locales from '@nuxt/ui/locale'

const { locale } = useI18n()
in the script and
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" />
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" />
which correctly renders my language picker and when i change an option it correctly shows in my html the lang changes. however in this case do i still need to setup anything for i18n in my app.vue? or in my nuxt config as when i move pages it changes back. and the url isn't changing to prepend the route with the locale?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the knowledge sources, using <ULocaleSelect v-model="locale" :locales="Object.values(locales)" /> with Nuxt UI will correctly update the UI component language, and you’ll see the <html lang="..."> attribute change. However, this only affects the UI component translations and does not handle Nuxt I18n’s routing or content translation features. To answer your questions: - Do you still need to set up anything for i18n in your app.vue or nuxt config? - Yes. If you want full i18n support (including URL locale prefixes, content translation, and persistence across navigation), you must configure the Nuxt I18n module in your nuxt.config.ts and ensure your app is using Nuxt I18n’s locale management. Just using Nuxt UI’s locale system will not update the route or persist the language across pages. - Why does the language revert when you move pages, and why doesn’t the URL change? - This happens because Nuxt UI’s locale system is independent of Nuxt I18n’s routing. Without Nuxt I18n properly set up, changing the language only affects the UI components and does not update the route or persist the language selection. What you should do: 1. Configure Nuxt I18n in your nuxt.config.ts:
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxtjs/i18n'
],
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}
})

export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxtjs/i18n'
],
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}
})

Nuxt UI I18n usage 2. Use Nuxt I18n’s setLocale or locale for language switching.
The <ULocaleSelect> can be bound to Nuxt I18n’s locale so that changing the language updates the route and persists the selection. 3. Ensure your app uses the correct locale for both UI and content.
Pass the current locale to <UApp :locale="locales[locale]" /> in your layout or app.vue so that UI components and content translations stay in sync. Summary:
- Nuxt UI’s locale system only affects UI components. - For full i18n (including URL changes and persistence), you must configure and use Nuxt I18n in your nuxt.config.ts and app. - Without Nuxt I18n, language changes will not persist across navigation or update the URL. If you follow the official setup, your language picker will work as expected, and the locale will persist and update the URL when navigating between pages Nuxt UI I18n usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai how do i use the custom error page from nuxt ui pro in my app?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To use the custom error page from Nuxt UI Pro in your Nuxt app, you should create or update the ~/error.vue file in your project’s root directory (alongside app.vue). In this file, you can use the <UError /> component provided by Nuxt UI Pro to display a styled error page. Here’s an example based on the official documentation:
<script setup lang="ts">
import type { NuxtError } from '#app'

const props = defineProps<{
error: NuxtError
}>()
</script>

<template>
<UApp>
<UHeader />

<UError :error="error" />

<UFooter />
</UApp>
</template>
<script setup lang="ts">
import type { NuxtError } from '#app'

const props = defineProps<{
error: NuxtError
}>()
</script>

<template>
<UApp>
<UHeader />

<UError :error="error" />

<UFooter />
</UApp>
</template>
- The error prop is automatically passed to error.vue by Nuxt. - You can wrap <UError /> with your app’s layout components (like <UApp>, <UHeader>, <UFooter>) to maintain a consistent look. - The <UError /> component will display the error status code, message, and a button to go back home by default. You can further customize the error page by passing additional props to <UError /> (such as redirect or clear) or by customizing your layout as needed see: Nuxt UI Pro Error Component Usage. Note:
Do not place error.vue inside the pages/ directory; it should be at the root of your source directory see: Nuxt error.vue guide. This setup will ensure your app uses the custom Nuxt UI Pro error page for all handled errors. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai do i make that in the root /app folder in nuxt 4 or in the pages folder?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You should place your error.vue file in the root of your source directory, not inside the pages folder. In Nuxt 4 with the new directory structure, this means placing error.vue inside the /app folder (e.g., app/error.vue). The knowledge sources explicitly state that error.vue is not a route and should not be placed in the pages/ directory. For the new structure, it should be alongside app.vue in your source directory see: error.vue directory guide.
Although it is called an 'error page' it's not a route and shouldn't be placed in your ~/pages directory. For the same reason, you shouldn't use definePageMeta within this page.
Nuxt error.vue guide
So, in Nuxt 4 with the default app/ source directory, use:
app/error.vue
app/error.vue
and not app/pages/error.vue. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai can i make it use my default layout so it will have my navbar, footer etc that i have setup already for all my pages?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can make your custom error.vue use your default layout (including your navbar, footer, etc.). According to the Nuxt documentation, you can use the <NuxtLayout> component inside your error.vue and specify the layout name (e.g., "default"):
<template>
<NuxtLayout name="default">
<!-- Your error content here -->
</NuxtLayout>
</template>
<template>
<NuxtLayout name="default">
<!-- Your error content here -->
</NuxtLayout>
</template>
For example, if you are using Nuxt UI Pro’s <UError /> component, your error.vue might look like this:
<script setup lang="ts">
import type { NuxtError } from '#app'

const props = defineProps<{
error: NuxtError
}>()
</script>

<template>
<NuxtLayout name="default">
<UError :error="error" />
</NuxtLayout>
</template>
<script setup lang="ts">
import type { NuxtError } from '#app'

const props = defineProps<{
error: NuxtError
}>()
</script>

<template>
<NuxtLayout name="default">
<UError :error="error" />
</NuxtLayout>
</template>
This approach ensures your error page uses the same layout as your other pages, so your navbar, footer, and other shared elements will appear on the error page as well. This is explicitly supported and recommended in the migration and directory structure documentation see: error.vue guide and migration guide.
If you want to ensure that this page uses a layout, you can use <NuxtLayout> directly within error.vue
Migration: Pages and Layouts
---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so if someone navigates to say example.com/dfhjghjidfsgifsdg some random url I don't have on my site the 404 error page shows up, however if i then click back to home I'm redirected but i guess since i used my default layout and the entry point was a 404 page my app.vue didn't get executed so my components don't have their required data? so when redirected back home which uses the same layout i still won't have data until a hard refresh? so then i guess either i need to move my script code etc from app.vue to my layout to solve that?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The knowledge sources do not explicitly describe the exact lifecycle behavior when navigating from a 404 error page (using a layout) back to a normal page, nor do they detail whether app.vue is re-executed in this scenario. However, the documentation does clarify that rendering an error page is an entirely separate page load, and any registered middleware will run again when the error is cleared or redirected Error Handling Docs. If you have logic in app.vue that is required for your components to function, and you notice that this logic is not executed when navigating from the error page back to a normal page, it is recommended to move such logic into your layout file. This is because layouts are consistently used across both error and normal pages, ensuring that shared logic and data are always available Layouts Guide. Summary:
- If your components depend on logic or data from app.vue, and this is missing after navigating from an error page, move the required logic to your layout file. - This ensures that the logic is executed regardless of whether the entry point was a normal page or an error page, as layouts are used in both cases. - The knowledge sources do not provide more granular details about the execution order of app.vue versus layouts in this scenario. If you continue to experience issues, consider reviewing your data-fetching and initialization strategies to ensure they are compatible with Nuxt's error handling and layout system. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai if i do that then do i move the nuxtloadingindicator, nuxtrouteannouncer to my layout too? and in my app.vue i have UApp setting my toaster and locale up so i assume that's not a great solution. plus then my code would be repeated if i add more layouts?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You are correct in your concerns. According to the knowledge sources, components like <NuxtLoadingIndicator> and <NuxtRouteAnnouncer> are typically placed in app.vue to ensure they are present globally across all layouts and pages. The official documentation shows these components in app.vue for this reason see: Nuxt Loading Indicator, NuxtRouteAnnouncer usage. Similarly, <UApp> (which provides global configuration for things like toasts and locale) is also intended to wrap your entire application in app.vue see: UApp usage. If you move these components into a specific layout, you would need to repeat the setup in every layout file, which is not ideal and goes against the recommended structure. The knowledge sources do not provide a better alternative for ensuring global providers and indicators are always present, especially when using custom error pages with layouts. Summary:
- Keep global providers like <UApp>, <NuxtLoadingIndicator>, and <NuxtRouteAnnouncer> in app.vue to avoid code duplication and ensure global availability. - If you move logic to layouts, you risk repeating code and losing the benefits of global configuration. - The knowledge sources do not describe a built-in solution for sharing logic between app.vue and layouts without duplication. If you encounter issues with missing data or logic after navigating from an error page, consider reviewing your data-fetching strategy or using composables for shared logic, but keep global providers in app.vue as recommended. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai clean way to add a label to the localeselector
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- The knowledge sources do not explicitly document a built-in label prop for <ULocaleSelect>. However, a clean and idiomatic way to add a label to the locale selector is to wrap it in a <UFormField> component, which is designed to provide labels, help text, and other form field features for input components in Nuxt UI. Example:
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>

<template>
<UFormField label="Language">
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" />
</UFormField>
</template>
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>

<template>
<UFormField label="Language">
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" />
</UFormField>
</template>
This approach is consistent with how labels are added to other input components in Nuxt UI, as shown in the documentation for UFormField usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so i have i18n setup right so all my links are set to use the right locale like /fr/privacy-policy but i use nuxt content for my privacy-policy using mark down, and currently going to /fr/privacy-policy returns a 404 so how do i ensure it's directed to the right place?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To ensure that /fr/privacy-policy (and other localized routes) work with Nuxt Content and Nuxt I18n, you need to make sure your content structure and routing support localized paths. The knowledge sources do not provide a direct, built-in way for Nuxt Content to automatically generate localized routes for markdown files based on the current locale. By default, Nuxt Content will generate routes based on your file structure (e.g., content/privacy-policy.md/privacy-policy). When using Nuxt I18n with route prefixes (like /fr/privacy-policy), you need to ensure that your content and routing are compatible. What you can do: 1. Create localized versions of your markdown files:
Place your localized markdown files in language-specific subfolders, such as:
content/privacy-policy.md // default (en)
content/fr/privacy-policy.md // French
content/es/privacy-policy.md // Spanish

content/privacy-policy.md // default (en)
content/fr/privacy-policy.md // French
content/es/privacy-policy.md // Spanish

This way, you can query the correct file based on the current locale. 2. Update your content query logic:
In your catch-all or dynamic page (e.g., pages/[...slug].vue), use the current locale to determine which content file to load. For example:
const { locale } = useI18n()
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () =>
queryCollection('content')
.path(`/${locale.value}${route.path}`)
.first()
)

const { locale } = useI18n()
const route = useRoute()
const { data: page } = await useAsyncData(route.path, () =>
queryCollection('content')
.path(`/${locale.value}${route.path}`)
.first()
)

(Note: The exact implementation may vary; the knowledge sources do not provide a full code example for this pattern.) 3. Ensure your Nuxt I18n configuration is correct:
Your nuxt.config.ts should have the correct strategy and locales set up, as you already have. Summary:
- Nuxt Content does not automatically handle i18n route prefixes for markdown files. - You need to organize your content files per locale and adjust your content queries to load the correct file based on the current locale. - If you do not provide a localized version, the route will return a 404. The knowledge sources do not provide a more automated or built-in solution for this scenario, so a manual approach as described above is necessary. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai i think i fried something, my content toc default text used to work properly but now it shows "contentToc.title" and color dropdown shows "colorMode.system" what might i have broken?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- When you see default text like "contentToc.title" or "colorMode.system" instead of the expected translated labels in Nuxt UI components, it usually means that the translation keys are not being resolved. This typically happens if the locale files are missing, not loaded, or the i18n integration is misconfigured. According to the knowledge sources, Nuxt UI relies on its own locale files for component translations, and these are mapped via the @nuxt/ui/locale package. If the locale is not set up or passed correctly, or if the integration with Nuxt I18n is broken, you will see the raw translation keys instead of the actual text Supported languages. What might have gone wrong: - The locale prop is not being passed to <UApp> or the current locale is not correctly set. - The integration between Nuxt UI and Nuxt I18n is missing or broken. - The locale files from @nuxt/ui/locale are not being imported or used. How to fix: 1. Make sure you are importing the locales and passing the correct one to <UApp>:
<script setup>
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>
<template>
<UApp :locale="locales[locale]" />
</template>

<script setup>
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>
<template>
<UApp :locale="locales[locale]" />
</template>

Dynamic locale example 2. Ensure your Nuxt I18n configuration is correct and that the locale value matches one of the keys in @nuxt/ui/locale. 3. If you recently changed your i18n setup, double-check that you did not remove or misconfigure the locale integration. If these steps are not followed, Nuxt UI components will display the raw translation keys instead of the translated text. Summary:
This issue is almost always due to a missing or broken locale/i18n integration with Nuxt UI. Double-check your <UApp :locale="..."/> setup and your i18n configuration to resolve it see: Nuxt UI I18n usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai so how do i use the default integrated nuxt ui pro language translations plus my custom translations in my files?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To use the default integrated Nuxt UI Pro language translations (for UI components) plus your own custom translations (for your app’s content or custom strings), you need to combine Nuxt UI’s locale system with Nuxt I18n’s translation system. Here’s how you do it, based on the knowledge sources: --- 1. Use Nuxt UI Pro’s Locale for UI Components - Import the locales from @nuxt/ui/locale (or @nuxt/ui-pro/locale if using Pro). - Pass the current locale to <UApp> so all Nuxt UI components use the correct language.
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>

<template>
<UApp :locale="locales[locale]" />
</template>
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>

<template>
<UApp :locale="locales[locale]" />
</template>
This ensures all Nuxt UI component default texts (like button labels, navigation, etc.) are translated automatically according to the selected locale see: Nuxt UI I18n usage. --- 2. Use Nuxt I18n for Your Custom Translations - Set up your own translation files (e.g., in a locales/ or i18n/ directory). - Configure Nuxt I18n in your nuxt.config.ts to load these files and handle route localization, content translation, etc.
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxtjs/i18n'
],
i18n: {
locales: [
{ code: 'en', name: 'English', file: 'en.json' },
{ code: 'fr', name: 'Français', file: 'fr.json' }
],
defaultLocale: 'en',
lazy: true,
langDir: 'locales/'
}
})
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxtjs/i18n'
],
i18n: {
locales: [
{ code: 'en', name: 'English', file: 'en.json' },
{ code: 'fr', name: 'Français', file: 'fr.json' }
],
defaultLocale: 'en',
lazy: true,
langDir: 'locales/'
}
})
You can then use $t('your.custom.key') or t('your.custom.key') in your templates and scripts for your own translations. --- 3. How They Work Together - Nuxt UI Pro’s locale: Handles UI component translations (no need to add these keys to your own files). - Nuxt I18n: Handles your app’s custom translations and content. - Both systems work in parallel, and you only need to keep your custom translations in your own files. --- Summary:
- Pass the Nuxt UI locale to <UApp> for UI component translations. - Use Nuxt I18n for your own translation keys and content. - You do not need to merge the two; each system handles its own scope see: Supported languages. If you follow this setup, you’ll get both the default Nuxt UI Pro translations and your custom translations working seamlessly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai ah cool thanks i just had to import from /ui-pro not /ui that fixed it
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- You're welcome! Yes, when using Nuxt UI Pro, you should import locales from @nuxt/ui-pro/locale instead of @nuxt/ui/locale to ensure all Pro component translations work correctly. This is confirmed in the official documentation, which shows examples using @nuxt/ui-pro/locale for projects utilizing Nuxt UI Pro see: Nuxt UI Pro I18n usage. Glad to hear that fixed your issue! ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai with the colormode dropdown can i set it to default to dark mode if no preference has been explicitly set by the user otherwise follow what the user explicitly set?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can set the color mode dropdown (such as <UColorModeSelect>) to default to dark mode if no preference has been set by the user, and otherwise follow the user's explicit choice. According to the Nuxt UI documentation, you can achieve this by configuring the color mode in your nuxt.config.ts:
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark', // Default to dark mode
fallback: 'dark', // Fallback to dark if no preference is found
// Do NOT set 'forced: true', so users can still change the mode
}
}
})
export default defineNuxtConfig({
modules: ['@nuxt/ui'],
ui: {
colorMode: {
preference: 'dark', // Default to dark mode
fallback: 'dark', // Fallback to dark if no preference is found
// Do NOT set 'forced: true', so users can still change the mode
}
}
})
With this setup: - If the user has not set a preference (i.e., no value in localStorage), the site will default to dark mode. - If the user explicitly selects a mode (via the dropdown or otherwise), their choice will be saved and respected on future visits. This behavior is described in the documentation, which explains that the preference and fallback options control the default and fallback color mode, while omitting forced: true allows user selection to persist Nuxt UI Color Mode. Summary:
Set preference: 'dark' and fallback: 'dark' in your config, and do not use forced: true. This will default to dark mode unless the user has chosen otherwise, and the dropdown will reflect and allow changing the mode. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai when i load my page and then use the language dropdown to change language and then refresh the page my language didn't change to the one i selected but remains? it should keep the language i selected right when im using i18n
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, when using Nuxt I18n with the detectBrowserLanguage option and useCookie: true, the language selected by the user should be stored in a cookie (by default, i18n_redirected). This ensures that when the user refreshes the page, their selected language is remembered and applied. If you are experiencing an issue where the language does not persist after a refresh, it usually means that either: - The cookie is not being set correctly, - The Nuxt I18n configuration is not picking up the cookie on page load, - Or the configuration is not in the correct file. From the knowledge sources, a common mistake is placing the i18n configuration in the wrong file. The locales, defaultLocale, and detectBrowserLanguage options must be in your nuxt.config.ts, not in a separate i18n.config.ts file. If these options are not in the correct place, the language detection and persistence will not work as expected see: Stack Overflow answer and Nuxt UI I18n usage. What to check: - Ensure your i18n options are in nuxt.config.ts:
i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}

i18n: {
strategy: 'prefix_except_default',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}

- Make sure you are not duplicating or overriding these options in another config file. - After changing the language, check your browser cookies for i18n_redirected—it should be set to the selected language code. If these are set up correctly, the language should persist after a page refresh see: Stack Overflow answer. If you are still having issues, double-check your configuration placement and ensure there are no typos or conflicting settings. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai what if i don't want a prefix in my urls will it still work?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, it will still work if you do not want a prefix in your URLs. You can achieve this by setting the strategy option to 'no_prefix' in your Nuxt I18n configuration. This means your URLs will not include the locale code (e.g., /privacy-policy instead of /en/privacy-policy), and language detection and persistence (such as using cookies) will continue to function as expected see: Stack Overflow answer. Here’s an example configuration:
i18n: {
strategy: 'no_prefix',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}
i18n: {
strategy: 'no_prefix',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English' },
{ code: 'fr', name: 'Français' },
{ code: 'es', name: 'Español' },
],
lazy: true,
}
With this setup, your app will handle language switching and persistence without adding a locale prefix to the URLs. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai
i18n: {
strategy: 'no_prefix',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{
code: 'en',
name: 'English',
file: 'en.json',
iso: 'en-US',
dir: 'ltr',
},
{
code: 'fr',
name: 'Français',
file: 'fr.json',
iso: 'fr-FR',
dir: 'ltr',
},
{
code: 'es',
name: 'Español',
file: 'es.json',
iso: 'es-ES',
dir: 'ltr',
},
],
lazy: true,
langDir: 'locales/',
},
i18n: {
strategy: 'no_prefix',
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{
code: 'en',
name: 'English',
file: 'en.json',
iso: 'en-US',
dir: 'ltr',
},
{
code: 'fr',
name: 'Français',
file: 'fr.json',
iso: 'fr-FR',
dir: 'ltr',
},
{
code: 'es',
name: 'Español',
file: 'es.json',
iso: 'es-ES',
dir: 'ltr',
},
],
lazy: true,
langDir: 'locales/',
},
this is my setup as i have my own translations in addition in i18n/locales could that be causing issues?
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Based on the knowledge sources, your configuration for using custom translations with lazy: true and langDir: 'locales/' is correct and should not cause issues by itself. This setup is supported and commonly used with Nuxt I18n, allowing you to keep your translation files (like en.json, fr.json, es.json) in a locales/ directory and load them lazily see: Nuxt UI I18n usage. The important points are: - Your locales array correctly specifies the file property for each language. - langDir: 'locales/' tells Nuxt I18n where to find these files. - lazy: true enables lazy loading of translation files. This setup should work with or without a URL prefix, depending on your strategy (in your case, 'no_prefix'). The knowledge sources do not mention any conflicts or issues with this approach. If you are experiencing issues, they are likely not caused by having your own translations in locales/ with this configuration. Instead, you should check for: - Typos in file names or paths. - That the translation files exist and are valid JSON. - That your i18n configuration is in the correct place (nuxt.config.ts). Summary:
Your setup with custom translations in locales/ and the given i18n config is valid and should not cause issues according to the knowledge sources see: Nuxt UI I18n usage. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai can you give me the basic setup in terms of i18n and a language dropdown so its stored to cookie properly when i change language and refresh the page
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Certainly! Here’s a basic setup for Nuxt I18n with a language dropdown that stores the selected language in a cookie and persists it after a page refresh, based on the knowledge sources: --- 1. nuxt.config.ts Place your i18n configuration directly in nuxt.config.ts (not in a separate file):
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxtjs/i18n'
],
i18n: {
strategy: 'no_prefix', // or 'prefix_except_default' if you want locale in URL
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English', file: 'en.json' },
{ code: 'fr', name: 'Français', file: 'fr.json' },
{ code: 'es', name: 'Español', file: 'es.json' },
],
lazy: true,
langDir: 'locales/',
}
})
export default defineNuxtConfig({
modules: [
'@nuxt/ui',
'@nuxtjs/i18n'
],
i18n: {
strategy: 'no_prefix', // or 'prefix_except_default' if you want locale in URL
defaultLocale: 'en',
detectBrowserLanguage: {
useCookie: true,
cookieKey: 'i18n_redirected',
fallbackLocale: 'en',
redirectOn: 'root',
},
locales: [
{ code: 'en', name: 'English', file: 'en.json' },
{ code: 'fr', name: 'Français', file: 'fr.json' },
{ code: 'es', name: 'Español', file: 'es.json' },
],
lazy: true,
langDir: 'locales/',
}
})
This ensures the language is stored in a cookie and persists after refresh Stack Overflow answer. --- 2. Language Dropdown Component In your component (e.g., footer or header):
<script setup lang="ts">
import { useI18n } from '#imports'
const { locale, locales } = useI18n()
</script>

<template>
<label for="lang-select">Language</label>
<select id="lang-select" v-model="locale">
<option v-for="l in locales" :key="l.code" :value="l.code">
{{ l.name }}
</option>
</select>
</template>
<script setup lang="ts">
import { useI18n } from '#imports'
const { locale, locales } = useI18n()
</script>

<template>
<label for="lang-select">Language</label>
<select id="lang-select" v-model="locale">
<option v-for="l in locales" :key="l.code" :value="l.code">
{{ l.name }}
</option>
</select>
</template>
Or, if you use Nuxt UI’s <ULocaleSelect>:
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>

<template>
<UFormField label="Language">
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" />
</UFormField>
</template>
<script setup lang="ts">
import * as locales from '@nuxt/ui/locale'
const { locale } = useI18n()
</script>

<template>
<UFormField label="Language">
<ULocaleSelect v-model="locale" :locales="Object.values(locales)" />
</UFormField>
</template>
Nuxt UI I18n usage --- 3. How it works - When you change the language, Nuxt I18n sets a cookie (i18n_redirected). - On page refresh, Nuxt I18n reads the cookie and sets the language accordingly. - The dropdown stays in sync with the current language. --- If you follow this setup, your language selection will persist across page reloads and be stored in a cookie, as described in the knowledge sources. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai idk ive tried a bunch of stuff but when i change the language in the localeselector the i18n_redirected cookie locale doesn't change so why might that be
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- If changing the language in your locale selector does not update the i18n_redirected cookie, the most common cause—according to the knowledge sources—is that the Nuxt I18n configuration is not set up correctly, or the configuration is not in the correct file. Specifically, the detectBrowserLanguage options (including useCookie: true and cookieKey: 'i18n_redirected') must be in your nuxt.config.ts, not in a separate i18n.config.ts file. If these options are not in the right place, the cookie will not be set or updated when you change the language Stack Overflow answer. Key things to check: - Ensure your i18n configuration (with detectBrowserLanguage) is in nuxt.config.ts. - Make sure you are using the locale from useI18n() as the v-model for your selector, so that changing the selector actually triggers a locale change in Nuxt I18n. - After changing the language, check your browser’s cookies for i18n_redirected—it should update to the new locale code. If these are set up correctly, the cookie should update as expected when you change the language. If not, double-check your configuration placement and ensure there are no typos or conflicting settings Stack Overflow answer. The knowledge sources do not mention other causes for this issue. If you have confirmed the above and it still does not work, the sources do not provide further troubleshooting steps. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai what component do i use for a link to an external site that has that icon with the arrow when its target is _blank? im building some footer links
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To create a link to an external site that automatically displays the external link icon (the arrow) when target="_blank", you should use the FooterColumns component from Nuxt UI Pro for your footer links. This component, when given a link with target: '_blank', will display the external icon next to the link label by default. Here’s an example from the documentation:
<script setup lang="ts">
import type { FooterColumn } from '@nuxt/ui-pro'

const columns: FooterColumn[] = [
{
label: 'Community',
children: [
{
label: 'Nuxt on GitHub',
to: '<https://github.com/nuxt',>
target: '_blank'
}
]
}
]
</script>

<template>
<UFooterColumns :columns="columns" />
</template>
<script setup lang="ts">
import type { FooterColumn } from '@nuxt/ui-pro'

const columns: FooterColumn[] = [
{
label: 'Community',
children: [
{
label: 'Nuxt on GitHub',
to: '<https://github.com/nuxt',>
target: '_blank'
}
]
}
]
</script>

<template>
<UFooterColumns :columns="columns" />
</template>
The external icon is shown automatically for links with target="_blank" in components like <UFooterColumns>, and you can further customize the icon via the ui prop if needed FooterColumns API. If you want to use a lower-level component, the Link component from Nuxt UI also supports this behavior, showing the external icon when target="_blank" is set. Summary:
Use <UFooterColumns> or <ULink> with target="_blank" for external links; the external arrow icon will be shown automatically FooterColumns usage Link props. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP5mo ago
@kapa.ai can i get an example of the link component then that will act like that as i dont see the icons on mine
kapa.ai
kapa.ai5mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Certainly! Here’s an example of using the Nuxt UI <ULink> component to create an external link that should display the external arrow icon when target="_blank" is set:
<template>
<ULink
to="<https://github.com/nuxt/ui">
target="_blank"
>
Nuxt UI on GitHub
</ULink>
</template>
<template>
<ULink
to="<https://github.com/nuxt/ui">
target="_blank"
>
Nuxt UI on GitHub
</ULink>
</template>
According to the documentation, <ULink> will render an external icon automatically when the target="_blank" prop is used Link component usage. If you are not seeing the icon, ensure you are using the latest version of Nuxt UI and that your project is set up correctly. You can also customize the styles or use the raw prop to provide your own classes if needed:
<template>
<ULink
raw
to="<https://github.com/nuxt/ui">
target="_blank"
active-class="font-bold"
inactive-class="text-muted"
>
Nuxt UI on GitHub
</ULink>
</template>
<template>
<ULink
raw
to="<https://github.com/nuxt/ui">
target="_blank"
active-class="font-bold"
inactive-class="text-muted"
>
Nuxt UI on GitHub
</ULink>
</template>
But by default, the external icon should appear for external links with target="_blank" Link props. If it does not, double-check your Nuxt UI installation and configuration. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai5mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai i have some legal pages like privacy policy etc made using nuxt content, should i somehow optimise those to be rendered on the server only or what's recommended for those types of pages that won't change
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- For legal pages like privacy policy, terms of service, etc., that are created using Nuxt Content and are not expected to change frequently, the recommended approach is to statically generate (prerender) these pages. This means they will be rendered at build time and served as static HTML files, which is optimal for SEO, performance, and reliability. According to the Nuxt documentation, static site generation is ideal for content-oriented pages that do not change often, such as legal documents, blogs, and marketing pages. You can achieve this by running nuxi generate during your build process, which will prerender your pages and allow you to deploy them to any static hosting provider Prerendering Rendering Modes. You do not need to force server-only rendering for these pages. Server-side rendering (SSR) is more suitable for pages that require dynamic data or frequent updates. For static legal pages, prerendering is simpler and more efficient. Summary:
- Use static site generation (prerendering) for legal pages that rarely change. - This approach is recommended for SEO, performance, and ease of deployment. - No need to force server-only rendering for such static content. This recommendation is directly supported by the Nuxt documentation on rendering modes and prerendering. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai so how do i specify only these to pre render? does the normal build command then cover that
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- To specify only certain pages (like your legal pages) to be prerendered, you should use the routeRules option in your nuxt.config.ts. For example, to prerender only /privacy-policy, /terms-of-service, and /site-rules, you can do:
export default defineNuxtConfig({
routeRules: {
'/privacy-policy': { prerender: true },
'/terms-of-service': { prerender: true },
'/site-rules': { prerender: true }
}
})
export default defineNuxtConfig({
routeRules: {
'/privacy-policy': { prerender: true },
'/terms-of-service': { prerender: true },
'/site-rules': { prerender: true }
}
})
See: Prerendering When you run the normal build command (nuxi build), it does not prerender pages by default. To actually generate the static HTML for these pages, you need to run the nuxi generate command. This command will use your routeRules to prerender only the specified routes as static files see: nuxi generate. Summary:
- Use routeRules in your config to specify which pages to prerender. - Run nuxi generate (not just nuxi build) to actually prerender those pages as static HTML. - The normal build command prepares your app for SSR or serverless, but does not output static HTML for specific pages unless you use generate or build --prerender. This is the recommended and documented way to selectively prerender pages in Nuxt. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai can i somehow mark all my content pages which are in a content folder to be prerendered?
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, you can mark all your content pages in a specific folder to be prerendered by using a route rule with a wildcard in your nuxt.config.ts. For example, if your content pages are available at routes like /content/your-page, you can use:
export default defineNuxtConfig({
routeRules: {
'/content/**': { prerender: true }
}
})
export default defineNuxtConfig({
routeRules: {
'/content/**': { prerender: true }
}
})
This will ensure that all routes matching /content/** are prerendered when you run nuxi generate or nuxi build --prerender see: Prerendering with routeRules and Wildcard routeRules. Note:
If your content pages are at the root (e.g., /privacy-policy, /terms-of-service), you can use a similar wildcard or specify the routes individually. However, for dynamic or non-deterministic routes (like [slug].vue), you may still need to provide a starting point or ensure the crawler can discover all routes, as wildcards alone cannot enumerate unknown dynamic paths see: routeRules and wildcards. Summary:
- Use a wildcard in routeRules to mark all pages in a folder for prerendering. - Run nuxi generate to actually prerender those pages as static HTML. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.
WiFi Plug
WiFi PlugOP4mo ago
@kapa.ai with the nuxt og image module can i make a custom image which includes a profile pic and username that's generated based on the url so different urls could have a unique og image? or do they have to be pre rendered?
kapa.ai
kapa.ai4mo ago
Let me check the knowledge base for you again. One moment! :books: ---------------------- Yes, with the Nuxt OG Image module, you can generate custom Open Graph images dynamically based on the URL, such as including a profile picture and username for different pages. The knowledge sources indicate that Nuxt OG Image supports dynamic generation and does not require all images to be pre-rendered. This allows you to create unique OG images for each URL, for example, by passing the username and profile picture as parameters to the OG image endpoint. This dynamic capability is important for use cases like user profiles, where each page can have a unique OG image generated on-the-fly, rather than relying on a set of pre-rendered images. The module is designed to work with dynamic data and can generate images at request time, making it suitable for scenarios where the content (like username and profile picture) varies per URL see: Nuxt OG Image module and dynamic generation. Summary:
- You can generate custom OG images dynamically per URL (e.g., with a profile pic and username). - Pre-rendering is not required; images can be generated on demand. If you need to implement this, you would typically set up a dynamic route or API endpoint that receives the necessary parameters and generates the OG image accordingly. ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai4mo ago
<@679734274840330384> Kapa.ai is still learning and improving, please let me know how I did by reacting below.

Did you find this page helpful?