跳转到内容

Value assigned to locals is not accepted.

LocalsNotAnObject: locals 只能被赋值为一个对象。不接受如数字、字符串等其他值。

哪里发生了错误?

在开发模式下,当 locals 被赋值为一个非对象时抛出错误。

例如:

import { defineMiddleware } from "astro:middleware";
export const onRequest = defineMiddleware((context, next) => {
context.locals = 1541;
return next();
});