Skip to content

Commit 168169b

Browse files
committed
feat: handle negative default querya params
1 parent 463a730 commit 168169b

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/core/definePage.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,16 @@ function extractQueryParams(
330330
paramInfo.default = String(paramProp.value.value)
331331
} else if (paramProp.value.type === 'NullLiteral') {
332332
paramInfo.default = 'null'
333+
} else if (
334+
paramProp.value.type === 'UnaryExpression' &&
335+
(paramProp.value.operator === '-' ||
336+
paramProp.value.operator === '+' ||
337+
paramProp.value.operator === '!' ||
338+
paramProp.value.operator === '~') &&
339+
paramProp.value.argument.type === 'NumericLiteral'
340+
) {
341+
// support negative numeric literals: -1, -1.5
342+
paramInfo.default = `${paramProp.value.operator}${paramProp.value.argument.value}`
333343
} else {
334344
warn(
335345
`Unrecognized default value in definePage() for query param "${paramName}". Typeof value: ${paramProp.value.type}. This is a bug, open an issue on https://github.com/posva/unplugin-vue-router and provide the definePage() code.`

0 commit comments

Comments
 (0)