我有一个简单的中间件设置,它检查用户是否使用zustand存储中的布尔值登录,并相应地将用户重定向到登录页面。这是根据docs
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
import { useAuthStore } from "./zustand/store";
export function middleware(request: NextRequest) {
const loggedIn = useAuthStore.getState().loggedIn;
if (!loggedIn) {
const url = request.nextUrl.clone();
url.pathname = "/login";
return NextResponse.rewrite(url);
} else {
return NextResponse.rewrite(request.nextUrl.clone());
}
}
当我使用这个中间件时,我得到了
react-refresh.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at react-refresh.js?ts=1661359264454:1:1)
18:41:04.842 webpack.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at webpack.js?ts=1661359264454:1:1)
18:41:04.842 main.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at main.js?ts=1661359264454:1:1)
18:41:04.909 _app.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at _app.js?ts=1661359264454:1:1)
18:41:04.924 index.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at index.js?ts=1661359264454:1:1)
18:41:04.925 _buildManifest.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at _buildManifest.js?ts=1661359264454:1:1)
18:41:04.925 _ssgManifest.js?ts=1661359264454:1 Uncaught SyntaxError: Unexpected token '<' (at _ssgManifest.js?ts=1661359264454:1:1)
1条答案
按热度按时间tuwxkamq1#
作者:Uncaught SyntaxError: expected expression, got '<' while using Next.js middleware