mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-29 09:02:03 +00:00
fix(nuxt): handle undefined
paths in resolveTrailingSlashBehavior
This commit is contained in:
parent
3fc4231d33
commit
ba6a4132bb
@ -100,7 +100,8 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
|
||||
function resolveTrailingSlashBehavior (to: string, resolve: Router['resolve']): string
|
||||
function resolveTrailingSlashBehavior (to: RouteLocationRaw, resolve: Router['resolve']): Exclude<RouteLocationRaw, string>
|
||||
function resolveTrailingSlashBehavior (to: RouteLocationRaw, resolve: Router['resolve']): RouteLocationRaw | RouteLocation {
|
||||
function resolveTrailingSlashBehavior (to: undefined, resolve: Router['resolve']): undefined
|
||||
function resolveTrailingSlashBehavior (to: RouteLocationRaw | undefined, resolve: Router['resolve']): RouteLocationRaw | RouteLocation | undefined {
|
||||
if (!to || (options.trailingSlash !== 'append' && options.trailingSlash !== 'remove')) {
|
||||
return to
|
||||
}
|
||||
@ -109,13 +110,18 @@ export function defineNuxtLink (options: NuxtLinkOptions) {
|
||||
return applyTrailingSlashBehavior(to, options.trailingSlash)
|
||||
}
|
||||
|
||||
const path = 'path' in to ? to.path : resolve(to).path
|
||||
const path = 'path' in to && to.path !== undefined ? to.path : resolve(to).path
|
||||
|
||||
return {
|
||||
const resolvedPath = {
|
||||
...to,
|
||||
name: undefined, // named routes would otherwise always override trailing slash behavior
|
||||
path: applyTrailingSlashBehavior(path, options.trailingSlash)
|
||||
}
|
||||
|
||||
if ('name' in resolvedPath) {
|
||||
delete resolvedPath.name
|
||||
}
|
||||
|
||||
return resolvedPath
|
||||
}
|
||||
|
||||
return defineComponent({
|
||||
|
@ -237,9 +237,11 @@ const plugin: Plugin<{ router: Router }> = defineNuxtPlugin({
|
||||
|
||||
nuxtApp.hooks.hookOnce('app:created', async () => {
|
||||
try {
|
||||
const to = router.resolve(initialURL)
|
||||
// #4920, #4982
|
||||
if ('name' in to) { delete to.name }
|
||||
await router.replace({
|
||||
...router.resolve(initialURL),
|
||||
name: undefined, // #4920, #4982
|
||||
...to,
|
||||
force: true
|
||||
})
|
||||
// reset scroll behavior to initial value
|
||||
|
Loading…
Reference in New Issue
Block a user