One of Nuxt core feature is the file-system router. Every Vue file created inside the pages/ directory creates a corresponding URL (or route) that displays the content of the file. Nuxt leverages code-splitting on each page by using dynamic imports to ship the minimum of JavaScript for the requested route.


Nuxt routing is based on vue-router and generates the routes from every component created in the pages/ directory, based on their filename.

This file system routing uses naming conventions to create dynamic and nested routes:

pages/ directory
--| about.vue
--| posts/
----| [id].vue
Generated Router file
  "routes": [
      "path": "/about",
      "component": "pages/about.vue"
      "path": "/posts/:id",
      "component": "pages/posts/[id].vue"

The <NuxtLink> component links pages between them. It renders a <a> tag with the href attribute set to the route of the page. Once the application is hydrated, pages transitions are performed in JavaScript by updating the browser URL. This prevents full-page refreshes and allow for animated transitions.

When a <NuxtLink> enters the viewport on the client side, Nuxt will automatically prefetch components and payload (generated pages) of the linked pages ahead of time, resulting in faster navigation.

        <li><NuxtLink to="/about">About</NuxtLink></li>
        <li><NuxtLink to="/posts/1">Post 1</NuxtLink></li>
        <li><NuxtLink to="/posts/2">Post 2</NuxtLink></li>

Route Parameters

The useRoute() composable can be used in a <script setup> block or a setup() method of a Vue component to access the current route details.

<script setup>
const route = useRoute()

// When accessing /posts/1, will be 1

Route Middleware

Nuxt provides a customizable route middleware framework you can use throughout your application, ideal for extracting code that you want to run before navigating to a particular route.

Route middleware run within the Vue part of your Nuxt app. Despite the similar name, they are completely different from server middleware, which are run in the Nitro server part of your app.

There are three kinds of route middleware:

  1. Anonymous (or inline) route middleware, which are defined directly in the pages where they are used.
  2. Named route middleware, which are placed in the middleware/ directory and will be automatically loaded via asynchronous import when used on a page. (Note: The route middleware name is normalized to kebab-case, so someMiddleware becomes some-middleware.)
  3. Global route middleware, which are placed in the middleware/ directory (with a .global suffix) and will be automatically run on every route change.

Example of an auth middleware protecting the /dashboard page:

export default defineNuxtRouteMiddleware((to, from) => {
  // isAuthenticated() is an example method verifying if an user is authenticated
  if (isAuthenticated() === false) {
    return navigateTo('/login')
<script setup>
  middleware: 'auth'

  <h1>Welcome to your dashboard</h1>
Edit this page on GitHub Updated at Mon, Oct 3, 2022