Skip to content

Instantly share code, notes, and snippets.

@vladimirlukyanov
Last active April 23, 2018 07:23
Show Gist options
  • Save vladimirlukyanov/7eede6db3799cfcc93575253e82a0ecd to your computer and use it in GitHub Desktop.
Save vladimirlukyanov/7eede6db3799cfcc93575253e82a0ecd to your computer and use it in GitHub Desktop.
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