UNPKG

nuxt

Version:

Nuxt is a free and open-source framework with an intuitive and extendable way to create type-safe, performant and production-grade full-stack web applications and websites with Vue.js.

26 lines (25 loc) 862 B
import { createError } from "#app/composables/error"; import { defineNuxtRouteMiddleware } from "#app/composables/router"; export default defineNuxtRouteMiddleware(async (to, from) => { if (!to.meta?.validate) { return; } const result = await Promise.resolve(to.meta.validate(to)); if (result === true) { return; } const error = createError({ fatal: import.meta.client, // eslint-disable-next-line @typescript-eslint/no-deprecated status: result && (result.status || result.statusCode) || 404, // eslint-disable-next-line @typescript-eslint/no-deprecated statusText: result && (result.statusText || result.statusMessage) || `Page Not Found: ${to.fullPath}`, data: { path: to.fullPath } }); if (typeof window !== "undefined") { window.history.pushState({}, "", from.fullPath); } return error; });