mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-25 07:05:11 +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 => {
|
||||
if (!to) {
|
||||
to = '/'
|
||||
}
|
||||
if (isProcessingMiddleware()) {
|
||||
return to
|
||||
}
|
||||
@ -63,7 +66,7 @@ export const navigateTo = (to: RouteLocationRaw, options: NavigateToOptions = {}
|
||||
if (process.server) {
|
||||
const nuxtApp = useNuxtApp()
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
@ -176,8 +176,9 @@ export default defineNuxtPlugin(async (nuxtApp) => {
|
||||
delete nuxtApp._processingMiddleware
|
||||
|
||||
if (process.server) {
|
||||
if (to.fullPath !== initialURL) {
|
||||
await callWithNuxt(nuxtApp, navigateTo, [to.fullPath])
|
||||
const currentURL = to.fullPath || '/'
|
||||
if (currentURL !== initialURL) {
|
||||
await callWithNuxt(nuxtApp, navigateTo, [currentURL])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user