jointrashposs/middleware/redirect-trailing-slash.global.ts
kakkokari-gtyih 8e52c51c49 wip
2023-07-08 17:36:02 +09:00

8 lines
334 B
TypeScript

export default defineNuxtRouteMiddleware((to, from) => {
if (process.client && to.path !== '/' && !to.path.endsWith('/') && !to.path.includes(".")) {
const { path, query, hash } = to
const nextPath = path + '/' || '/'
const nextRoute = { path: nextPath, query, hash }
return navigateTo(nextRoute, { redirectCode: 301 })
}
})