这是中间件文件中的代码:
import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
// This function can be marked `async` if using `await` inside
export function middleware(request : NextRequest) {
const path = request.nextUrl.pathname;
const isPublicPath = path === '/login' || path === '/signup';
const token = request.cookies.get('token')?.value || '';
if (isPublicPath && token) {
return NextResponse.redirect(new URL('/', request.nextUrl));
}
if (!isPublicPath && !token) {
return NextResponse.redirect(new URL('/login', request.nextUrl));
}
}
// See "Matching Paths" below to learn more
export const config = {
matcher: ['/','/profile', 'login', '/signup'],
};
错误是
source
不以/不是路由{"source":"登录"}开头
错误:找到无效的中间件
有什么办法解决这个问题吗?