Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions packages/core/src/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,19 @@ export class Router {
? defaultVisitOptionsCallback(href.toString(), cloneDeep(options)) || {}
: {}

// Strip explicit undefined values so they don't overwrite defaults during spread.
// TypeScript's Partial<> allows { only: undefined } which would overwrite the
// default [] and later crash on .length access (see #3018).
const stripUndefined = <T extends Record<string, unknown>>(obj: T): Partial<T> => {
const result: Partial<T> = {}
for (const key of Object.keys(obj) as (keyof T)[]) {
if (obj[key] !== undefined) {
result[key] = obj[key]
}
}
return result
}

const mergedOptions: Visit = {
method: 'get',
data: {},
Expand All @@ -654,8 +667,8 @@ export class Router {
viewTransition: false,
component: null,
pageProps: null,
...options,
...configuredOptions,
...stripUndefined(options),
...stripUndefined(configuredOptions),
}

const [url, _data] = transformUrlAndData(
Expand Down
Loading