Skip to content

Commit b469918

Browse files
committed
feat: add redirects for nuxt error documentation
1 parent 9baba17 commit b469918

5 files changed

Lines changed: 45 additions & 2 deletions

File tree

app/pages/docs/[...slug].vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ watch(page, (page) => {
7979
}, { immediate: true })
8080
8181
// Get the -2 item of the breadcrumb
82-
const currentSectionTitle = computed(() => headerLinks.value[0].children.find(link => path.value.includes(link.to))?.label || findPageBreadcrumb(navigation.value, path.value).slice(-1)[0].title)
82+
const currentSectionTitle = computed(() => headerLinks.value[0].children.find(link => path.value.includes(link.to))?.label || findPageBreadcrumb(navigation.value, path.value).slice(-1)[0]?.title || page.value?.title)
8383
8484
const breadcrumb = computed(() => {
8585
const links = mapContentNavigation(findPageBreadcrumb(navigation.value, path.value)).map(link => ({

content.config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const docsV3Source = {
1010

1111
const docsV4Source = {
1212
cwd: process.env.NUXT_V4_PATH ?? undefined,
13-
repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/4.x' : undefined,
13+
// TODO: revert to 4.x branch before merging
14+
repository: !process.env.NUXT_V4_PATH ? 'https://github.com/nuxt/nuxt/tree/feat/error-context' : undefined,
1415
include: 'docs/**/*',
1516
exclude: ['docs/**/*.json'],
1617
prefix: '/docs/4.x'

nuxt.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export default defineNuxtConfig({
117117
'/docs/3.x/getting-started/introduction': { prerender: true },
118118
'/docs/4.x/getting-started/introduction': { prerender: true },
119119
'/docs/5.x/getting-started/introduction': { prerender: true },
120+
'/docs/4.x/errors': { prerender: true },
120121
'/modules': { prerender: true },
121122
'/modules/**': { isr: 60 * 60 },
122123
'/changelog': { isr: 60 * 60 },
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/**
2+
* Redirect unversioned error doc paths to the current default version.
3+
*
4+
* The Nuxt runtime links to https://nuxt.com/docs/errors/E1001 (unversioned).
5+
* This middleware redirects those paths to the current default docs version
6+
* (e.g., /docs/4.x/errors/E1001) so the content can be resolved.
7+
*/
8+
export default defineEventHandler((event) => {
9+
const path = getRequestURL(event).pathname
10+
11+
// Match /docs/errors/... but NOT /docs/3.x/errors/... or /docs/4.x/errors/...
12+
const match = path.match(/^\/docs\/errors\/(.+)$/)
13+
if (match) {
14+
// TODO: update to /docs/5.x when Nuxt 5 is the default
15+
return sendRedirect(event, `/docs/4.x/errors/${match[1]}`, 302)
16+
}
17+
})

server/routes/e/[code].get.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
* Short URL handler for Nuxt error codes.
3+
*
4+
* Redirects /e/NUXT_E1001 → /docs/4.x/errors/E1001
5+
* Redirects /e/NUXT_B1001 → /docs/4.x/errors/B1001
6+
*
7+
* The error code format is NUXT_ followed by E or B and 1-4 digits.
8+
* The NUXT_ prefix is stripped and the user is redirected to the
9+
* current default docs version.
10+
*/
11+
export default defineEventHandler((event) => {
12+
const code = getRouterParam(event, 'code')
13+
14+
// Validate: must be NUXT_ followed by E or B and 1-4 digits
15+
if (!code || !/^NUXT_[EB]\d{1,4}$/.test(code)) {
16+
throw createError({ statusCode: 404, statusMessage: 'Not found' })
17+
}
18+
19+
// Strip the NUXT_ prefix → E1001 or B1001
20+
const errorCode = code.replace('NUXT_', '')
21+
22+
// TODO: update to /docs/5.x when Nuxt 5 is the default
23+
return sendRedirect(event, `/docs/4.x/errors/${errorCode}`, 302)
24+
})

0 commit comments

Comments
 (0)