我有一个页面并且在这个页面中有动态导入: http://localhost:3000/rulesets/1
import dynamic from "next/dynamic";
const RegexInput = dynamic(import("./ExpressionEditor"), {
ssr: false,
});
export default RegexInput;
and this page has getServerSideProps:
export const getServerSideProps = authenticatedPage(async (context) => {
const id = requireNumberParam(context, "id");
...
requireNumberParam 方法:
export function requireNumberParam<P extends ParsedUrlQuery>(
context: GetServerSidePropsContext<P>,
name: keyof P
): number {
const str = context.params?.[name];
if (Array.isArray(str)) {
throw new Error(`Param ${name} is an array; expected single item`);
}
const num = str ? parseInt(str as string, 10) : NaN;
if (isNaN(num)) {
throw new Error(`Param ${name} is not a number`);
}
return num;
}
在这个页面里面,有一个对这个 url 的请求: http://localhost:3000/rulesets/worker-javascript.js
这是回应
...
<script id="__NEXT_DATA__" type="application/json">
{
"props": {
"pageProps": {},
"__N_SSP": true
},
"page": "/rulesets/[id]",
"query": {
"id": "worker-javascript.js"
},
"buildId": "development",
"isFallback": false,
"err": {
"name": "Error",
"message": "Param id is not a number",
"stack": "Error: Param id is not a number"
},
"gssp": true
}
</script>
...
它导致控制台出错 console error
worker-javascript.js 被检测为参数, 我应该怎么做才能解决这个问题?