Overview

In a Nuxt 3/4 + Nuxt Content environment with trailingSlash: "append" configured, links to static files such as PDFs and images within content may result in 404 errors.

Conditions for Occurrence

This occurs when all of the following conditions are met:

  1. Using Nuxt 3/4 + Nuxt Content
  2. trailingSlash: "append" is set in nuxt.config.ts
  3. There are links to static files (PDFs, images, etc.) in Markdown or content

Problem Details

Symptoms

When writing a link like the following in content:

<ahref="/uploads/document.pdf">Downloaddocument</a>

The generated HTML converts the link to:

/uploads/document.pdf/

A / is appended to the end, making the static file inaccessible and resulting in a 404 error.

Cause

In Nuxt Content, <a> tags in Markdown are converted to ProseA components.

The default ProseA component (in the @nuxtjs/mdc package) has the following implementation:

<t/e<tmN/epu<NmlxsupatlxltLotaeitLt>niekn>k:>href="props.href":target="props.target">

Since it uses NuxtLink, it is affected by the trailingSlash setting in nuxt.config.ts.

e}x)pe};nox,urpd}xtee,trfn}.diau,cemuxtofeltrnantLafutsiiila:nlgtlki.:{:ntdgse{{SfliansehN:ux"taCpopnefnidg"(,{Thissettingisthecause

Solution

Create a custom ProseA component that uses a regular <a> tag for links to static files.

Implementation

Create components/content/ProseA.vue:

<<c}ccc]c}c}t/so)ooo;o)o)/e<<tcnh}t};nnn""""""""""""""""ncr;nci}i}r;sma/N/ersr,a,sss................soesffecp<au<Nmitetdrtdrtttpjjpgwszddxxppcttnttnrrtrls>xsuppfyegyeedppnievioollppsxsusF(eA(euia-ltlxltp:pfepfqcbsfgegfbgpccssttvtitrrtohtdhtrptioLotareateauoat""g""p"""x"x"x""snerrudrunteftitLtso{:u::uinsa,,",,",,,",",",,Shsherer>>=nieepllrfet,,,,,trsorefnbfnh"kn>tsSt{SteiUiaetlex.a.rikut:t:dgRctfavftshssbes>p=rr:LFiteetretafS-i"iu=ic=id=raeUas;teldn"nnf=lFcHnrfRrealaeg,gdaueipFrpat;LtUtsnf,,elscElrierlssRiegifseoxeolfoWtWLc=nieRntpeplioiF:"en,ufe=sE=sitt+ihtPenin.x.nhihlrsrdtgschtchk(n(hee"o,i.ioreors"t"r"f>pmaomenmehe/e=sepnpfspfotr"f:"(Cpsu.iu;rtn);hp{o.ttotpa)rrnb=eonet"leofadLsdh){fpis[(o.(or=sge(ws(se".(U)eo)elrh)Rrmaer;L=Ce=ahtse>a(>lriofs(revl"{ee{efev(xa.e:")tdspdt";)ytaHa;atrr=crheg>otsfens"thtW(=rais:"eitttpfnhaar.i(rroenbtgpngaiesdsnt.sbeg=tWaU"aisRwprteLirghU)toe(R)hpteLs"x,{.>tt)ua)sr;egeats"->is

Key Points

  1. Static file detection: Determines whether a file is static based on the file extension
  2. Use regular <a> tag: For static files, use a regular <a> tag instead of NuxtLink to avoid the trailingSlash setting
  3. Add baseURL: When not using NuxtLink, baseURL is not automatically applied, so it must be added manually

Verification

After building, check the generated HTML:

ngprmeprung'ehnreerfa=t"e[^"]*\.pdf[^"]*"'output/public/path/to/page/index.html

Expected output (no trailing /):

href="/base-url/uploads/document.pdf"

Additional Notes

Why Use trailingSlash: “append”

  • From an SEO perspective, it is recommended to unify the presence or absence of trailing / in URLs
  • Prevents /page and /page/ from being treated as different URLs (duplicate content issue)
  • Many sites adopt append (adding trailing /)

Other Solutions

  1. Use absolute URLs: Write absolute URLs like https://example.com/uploads/document.pdf in content (though management becomes cumbersome if URLs differ per environment)

  2. Remove trailingSlash setting: Change the site-wide setting (need to consider impact on other pages)

Environment

  • Nuxt 4.x (the same issue may occur with Nuxt 3.x)
  • Nuxt Content v3
  • @nuxtjs/mdc

References