Identify and fix link issues for prerendered Nuxt 3 apps.

nuxt-link-checker

NPM versionNPM DownloadsGitHub stars

Identify and fix link issues for prerendered Nuxt 3 apps.


Status: Stable
Please report any issues 🐛
Made possible by my Sponsor Program 💖
Follow me @harlan_zw 🐦 • Join Discord for help

ℹ️ Looking for a complete SEO solution? Check out Nuxt SEO Kit.

Features

  • ✅ Discover broken links - 404s and internal redirects
  • 🚩 Warnings for bad practice links - absolute instead of relative and wrong trailing slash
  • 🕵️ Fail on build if broken links are found (optional)

Install

npm install --save-dev nuxt-link-checker

# Using yarn
yarn add --dev nuxt-link-checker

Setup

nuxt.config.ts

export default defineNuxtConfig({
  modules: [
    'nuxt-link-checker',
  ],
})

To have routes scanned for broken links automatically, they need to be pre-rendered by Nitro.

export default defineNuxtConfig({
  nitro: {
    prerender: {
      crawlLinks: true,
      routes: [
        '/',
        // any URLs that can't be discovered by crawler
        '/my-hidden-url'
      ]
    }
  }
})

Set host (optional)

You'll need to provide the host of your site so that the crawler can resolve absolute URLs that may be internal.

export default defineNuxtConfig({
  // Recommended 
  runtimeConfig: {
    public: {
      siteUrl: process.env.NUXT_PUBLIC_SITE_URL || 'https://example.com',
    }
  },
  // OR 
  linkChecker: {
    host: 'https://example.com',
  },
})

Exclude URLs from throwing errors

You can exclude URLs from throwing errors by adding them to the exclude array.

For example, if you have an /admin route that is a separate application, you can ignore all /admin links with:

export default defineNuxtConfig({
  linkChecker: {
    exclude: [
      '/admin/**'
    ],
  },
})

You can disable errors on broken links by setting failOn404 to false.

export default defineNuxtConfig({
  linkChecker: {
    failOn404: false,
  },
})

Module Config

failOn404

  • Type: boolean
  • Default: true

If set to true, the build will fail if any broken links are found.

exclude

  • Type: string[]
  • Default: []

An array of URLs to exclude from the check.

This can be useful if you have a route that is not pre-rendered, but you know it will be valid.

host

  • Type: string
  • Default: runtimeConfig.public.siteUrl || localhost
  • Required: false

The host of your site. This is required to validate absolute URLs which may be internal.

trailingSlash

  • Type: boolean
  • Default: false

Whether internal links should have a trailing slash or not.

Sponsors

License

MIT License © 2023-PRESENT Harlan Wilton