Guides
Add a page
Create a route, give it a title and a menu entry, and protect it with a permission.
This guide adds a Reports page at /reports.
1. Create the file
Nuxt creates a route for every file in pages/. Create pages/reports.vue:
<template>
<div>
<BasePageHeader :title="$t('reports.title')" :description="$t('reports.description')">
<template #actions>
<BaseButton button-type="primary" prepend-icon="download" @click="exportAll">
{{ $t('reports.export') }}
</BaseButton>
</template>
</BasePageHeader>
<BaseEmptyState
icon="file-chart-column"
:title="$t('reports.empty.title')"
:text="$t('reports.empty.text')"
/>
</div>
</template>
<script setup lang="ts">
definePageMeta({
breadcrumb: ['nav.reports'],
})
const { t } = useI18n()
const toast = useToast()
function exportAll() {
toast.show(t('apps.common.demoAction'))
}
</script>
The last breadcrumb item also becomes the browser title: Reports - My App.
2. Add the strings
Add the keys in every language. Interface strings go in the file of their domain; for a new domain create a file and add it to LOCALE_FILES in config/locales.config.ts.
{
"reports": {
"title": "Reports",
"description": "Download the numbers your team asks for every week.",
"export": "Export all",
"empty": {
"title": "No reports yet",
"text": "Reports you create appear here."
}
}
}
{
"nav": {
"reports": "Reports"
}
}
3. Add it to the menu
Menu items live in composables/useNavigation.ts. The sidebar, the horizontal menu and the command palette all read from it, so you add the page once:
{ subheader: t('nav.management'), icon: 'briefcase-business' },
{
icon: 'file-chart-column',
title: t('nav.reports'),
route: 'reports',
badge: t('nav.new'),
},
Field | Use |
|---|---|
route | The path without the leading slash. Children are linked as /<route>/<child route>. |
path | An absolute URL that overrides the route, query string allowed. |
icon | A Lucide name. Run npm run icons:sync after adding a new one. |
badge | A short chip such as t('nav.new') for recent additions. |
permission | Hides the item from users without that permission. |
children | Sub-items. Keep at most two levels. |
Link single pages directly. Do not wrap one page in a group with one child.
4. Protect it (optional)
To restrict the page, give the page and its menu item the same permission:
definePageMeta({
breadcrumb: ['nav.reports'],
permission: 'dashboard.view',
})
Users without the permission do not see the item and get a 403 if they type the URL. The Roles and permissions guide shows how to add a new permission.
5. Create from the command palette (optional)
If the page creates records, add it to the Create group of the command palette so Ctrl/⌘ K can open its form from anywhere: see Create actions.
6. Check it
The test tests/unit/navigation-coverage.test.ts fails when a page in pages/ is not reachable from the menu, or when the menu links to a page that does not exist. Run the gates:
$npm run icons:sync$npm run lint$npm run test
Pages outside the app shell
- A public page (no session): add
public: truetodefinePageMeta, andlayout: 'blank'if it should not show the sidebar. - A full-height app like email or kanban: add
fluid: trueandhideBreadcrumbs: true, and put the panes inside.app-panel. - A detail page: create
pages/reports/index.vueandpages/reports/[id].vue. Look the record up and throw a 404 when it is missing:
const report = computed(() => findReport(String(route.params.id)))
if (!report.value) throw createError({ statusCode: 404, fatal: true })