mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 13:45:18 +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
|
createWebHistory
|
||||||
} from 'vue-router'
|
} from 'vue-router'
|
||||||
import { createError } from 'h3'
|
import { createError } from 'h3'
|
||||||
import { isEqual, withoutBase } from 'ufo'
|
import { withoutBase } from 'ufo'
|
||||||
|
|
||||||
import type { PageMeta, Plugin, RouteMiddleware } from '../../../app/index'
|
import type { PageMeta, Plugin, RouteMiddleware } from '../../../app/index'
|
||||||
import { callWithNuxt, defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
|
import { callWithNuxt, defineNuxtPlugin, useRuntimeConfig } from '#app/nuxt'
|
||||||
@ -181,11 +181,8 @@ export default defineNuxtPlugin({
|
|||||||
fatal: false,
|
fatal: false,
|
||||||
statusMessage: `Page not found: ${to.fullPath}`
|
statusMessage: `Page not found: ${to.fullPath}`
|
||||||
})])
|
})])
|
||||||
} else if (process.server) {
|
} else if (process.server && to.redirectedFrom) {
|
||||||
const currentURL = to.fullPath || '/'
|
await callWithNuxt(nuxtApp, navigateTo, [to.fullPath || '/'])
|
||||||
if (!isEqual(currentURL, initialURL, { trailingSlash: true })) {
|
|
||||||
await callWithNuxt(nuxtApp, navigateTo, [currentURL])
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -130,6 +130,11 @@ describe('pages', () => {
|
|||||||
await page.close()
|
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 () => {
|
it('render 404', async () => {
|
||||||
const html = await $fetch('/not-found')
|
const html = await $fetch('/not-found')
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|||||||
await new Promise(resolve => setTimeout(resolve, 100))
|
await new Promise(resolve => setTimeout(resolve, 100))
|
||||||
return navigateTo(to.path.slice('/redirect/'.length - 1))
|
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') {
|
if (to.path === '/navigate-to-external') {
|
||||||
return navigateTo('/', { external: true })
|
return navigateTo('/', { external: true })
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user