mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
fix(nuxt): ensure url is not empty string (#4781)
This commit is contained in:
parent
5b63ae8ad5
commit
ebc27ce997
@ -56,6 +56,9 @@ export interface NavigateToOptions {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export const navigateTo = (to: RouteLocationRaw, options: NavigateToOptions = {}): Promise<void | NavigationFailure> | RouteLocationRaw => {
|
export const navigateTo = (to: RouteLocationRaw, options: NavigateToOptions = {}): Promise<void | NavigationFailure> | RouteLocationRaw => {
|
||||||
|
if (!to) {
|
||||||
|
to = '/'
|
||||||
|
}
|
||||||
if (isProcessingMiddleware()) {
|
if (isProcessingMiddleware()) {
|
||||||
return to
|
return to
|
||||||
}
|
}
|
||||||
@ -63,7 +66,7 @@ export const navigateTo = (to: RouteLocationRaw, options: NavigateToOptions = {}
|
|||||||
if (process.server) {
|
if (process.server) {
|
||||||
const nuxtApp = useNuxtApp()
|
const nuxtApp = useNuxtApp()
|
||||||
if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) {
|
if (nuxtApp.ssrContext && nuxtApp.ssrContext.event) {
|
||||||
const redirectLocation = router.resolve(to).fullPath
|
const redirectLocation = router.resolve(to).fullPath || '/'
|
||||||
return nuxtApp.callHook('app:redirected').then(() => sendRedirect(nuxtApp.ssrContext.event, redirectLocation, options.redirectCode || 301))
|
return nuxtApp.callHook('app:redirected').then(() => sendRedirect(nuxtApp.ssrContext.event, redirectLocation, options.redirectCode || 301))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -176,8 +176,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
|||||||
delete nuxtApp._processingMiddleware
|
delete nuxtApp._processingMiddleware
|
||||||
|
|
||||||
if (process.server) {
|
if (process.server) {
|
||||||
if (to.fullPath !== initialURL) {
|
const currentURL = to.fullPath || '/'
|
||||||
await callWithNuxt(nuxtApp, navigateTo, [to.fullPath])
|
if (currentURL !== initialURL) {
|
||||||
|
await callWithNuxt(nuxtApp, navigateTo, [currentURL])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user