Replies: 7 comments 9 replies
-
Well that's odd... middleware should not cause this. Could you add a bit more info.
AttemptsI've tried to reproduce your situation with: import { NextResponse } from "next/server";
import type { NextRequest } from "next/server";
export default async function middleware(req: NextRequest) {
if (req.nextUrl.pathname === "/") {
req.nextUrl.pathname = "/about";
return NextResponse.redirect(req.nextUrl);
}
return NextResponse.next();
}
export const config = {
matcher: ["/"],
}; And the about page is just: export const getServerSideProps = () => {
return { props: { foo: "bar" } };
};
export default function About(props: { foo: string }) {
return <div>About {props.foo}</div>;
} No luck. Somehow I have a hunch that the problem is in the _app file, are you passing along the Like this: import type { AppProps } from 'next/app'
export default function App({ Component, pageProps }: AppProps) {
return <Component {...pageProps} />
} |
Beta Was this translation helpful? Give feedback.
-
I'm facing the same problem, and it only happens in production. In development enviroment, all the props are working fine. |
Beta Was this translation helpful? Give feedback.
-
I had this issue and fixed it. You need to downgrade to 13.3.1 apparently. It might work for other 13.3.x but 1 was the first and only one I tried. Not really inclined to try any others. What I did:
|
Beta Was this translation helpful? Give feedback.
-
I'm having a similar issue with
|
Beta Was this translation helpful? Give feedback.
-
I'm facing the same problem in next 13.4.10, and it only happens in production and i cant redirect in middleware because my next/link not work and show client side error in production! |
Beta Was this translation helpful? Give feedback.
-
is there are any help about this because I honestly have no I dea why this issue happends andI kind of need the middleware in the app |
Beta Was this translation helpful? Give feedback.
-
Hi there, we're on Next.js 14.2.25 and do use Our component expects props but they are undefined which causes the page to break. On reload, they work as expected. This makes it hard to rely on Any clues if on whether |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Summary
I'm trying to do a simple redirect on every page if a certain condition is true using Nextjs middleware.
For some reason, whenever the
matcher
in middleware.ts matches a page, allprops
passed fromgetServerSideProps
on that page areundefined
when they reach the client side. When I remove pages from the matcher regex, they work as expected, and props are populated.Example
/middleware.ts:
/pages/index.tsx:
Additional information
getServerSideProps
is firing, and I see the correct values in the terminal, but I'm still gettingundefined
on the client-side specifically is the middleware executes. Is it possible to use both? Or their a better approach to redirecting from all pages than using middleware.ts?Beta Was this translation helpful? Give feedback.
All reactions