Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Nuxt.js 404 error handling | Nuxt.js 404 redirect | Nuxt.js middleware routing
// Add this file to /middleware
export default function ({params, route, redirect}) {
if(route.matched.length === 0) { // route is not found, redirect to homepage
redirect('302', '/');
}
}
export default {
head: {
title: 'Auth Routes',
meta: [
{charset: 'utf-8'},
{name: 'viewport', content: 'width=device-width, initial-scale=1'},
{hid: 'description', content: 'Auth Routes example'}
]
},
plugins: [],
build: {
analyze: false,
},
loading: {color: '#41B883'},
router: {
linkActiveClass: 'active',
middleware: ['404-redirect'] // important to add
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment