mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): do not redirect when vue-router
normalises url (#20247)
This commit is contained in:
parent
295473f924
commit
9110d41628
@ -8,7 +8,7 @@ import {
|
||||
createWebHistory
|
||||
} from 'vue-router'
|
||||
import { createError } from 'h3'
|
||||
import { isEqual, withoutBase } from 'ufo'
|
||||
import { withoutBase } from 'ufo'
|
||||
|
||||
import type { PageMeta, Plugin, RouteMiddleware } from '../../../app/index'
|
||||
import { callWithNuxt, defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
|
||||
@ -181,11 +181,8 @@ export default defineNuxtPlugin({
|
||||
fatal: false,
|
||||
statusMessage: `Page not found: ${to.fullPath}`
|
||||
})])
|
||||
} else if (process.server) {
|
||||
const currentURL = to.fullPath || '/'
|
||||
if (!isEqual(currentURL, initialURL, { trailingSlash: true })) {
|
||||
await callWithNuxt(nuxtApp, navigateTo, [currentURL])
|
||||
}
|
||||
} else if (process.server && to.redirectedFrom) {
|
||||
await callWithNuxt(nuxtApp, navigateTo, [to.fullPath || '/'])
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -130,6 +130,11 @@ describe('pages', () => {
|
||||
await page.close()
|
||||
})
|
||||
|
||||
it('returns 500 when there is an infinite redirect', async () => {
|
||||
const { status } = await fetch('/redirect-infinite', { redirect: 'manual' })
|
||||
expect(status).toEqual(500)
|
||||
})
|
||||
|
||||
it('render 404', async () => {
|
||||
const html = await $fetch('/not-found')
|
||||
|
||||
|
@ -9,6 +9,10 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
||||
await new Promise(resolve => setTimeout(resolve, 100))
|
||||
return navigateTo(to.path.slice('/redirect/'.length - 1))
|
||||
}
|
||||
if (to.path === '/redirect-infinite') {
|
||||
// the path will be the same in this new route and vue-router should send a 500 response
|
||||
return navigateTo('/redirect-infinite?test=true')
|
||||
}
|
||||
if (to.path === '/navigate-to-external') {
|
||||
return navigateTo('/', { external: true })
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user