Skip to content

getStaticPaths 路由参数的值无效。

GetStaticPathsInvalidRouteParam:KEY 的 getStaticPaths 路由参数无效。预期未定义,字符串或数字,收到 VALUE_TYPE (VALUE)

¥GetStaticPathsInvalidRouteParam: Invalid getStaticPaths route parameter for KEY. Expected undefined, a string or a number, received VALUE_TYPE (VALUE)

¥What went wrong?

由于 params 被编码到 URL 中,因此仅支持某些类型作为值。

¥Since params are encoded into the URL, only certain types are supported as values.

/route/[id].astro
---
export async function getStaticPaths() {
return [
{ params: { id: '1' } } // Works
{ params: { id: 2 } } // Works
{ params: { id: false } } // Does not work
];
}
---

在使用 其余参数 的路由中,undefined 可用于表示 URL 中不传递参数的路径:

¥In routes using rest parameters, undefined can be used to represent a path with no parameters passed in the URL:

/route/[...id].astro
---
export async function getStaticPaths() {
return [
{ params: { id: 1 } } // /route/1
{ params: { id: 2 } } // /route/2
{ params: { id: undefined } } // /route/
];
}
---

也可以看看:

¥See Also:

Astro 中文网 - 粤ICP备13048890号