小编Bla*_*021的帖子

nextJS 13 中的重定向(中间件)

我正在开发我的中间件,我想在用户登录后重定向用户。问题是 api 没有到达终点并且卡在中间件部分(根据我的观察)并且页面也没有重定向。

import { NextRequest, NextResponse } from "next/server";

export function middleware(req) {
  const url = req.url;

  if (url.includes("login")) {
    return NextResponse.redirect("localhost:3000/home", req.url);
  }

  return NextResponse.next();
}

export const config = {
  matcher: ["/", "/api/login"],
};
Run Code Online (Sandbox Code Playgroud)

middleware next.js

1
推荐指数
1
解决办法
9755
查看次数

标签 统计

middleware ×1

next.js ×1