Passing informations from middleware to SSR page
Unanswered
Britannia Petite posted this in #help-forum
Britannia PetiteOP
How can I pass informations from middleware to SSR page ?
I am using App Router
I am using App Router
4 Replies
Toyger
cookies or headers
Britannia PetiteOP
no it does not work
if I use request or response.cookie.set('lang', value)
it will return as a response Set-Cookie and I will not be able to know on that request information I need but on the next one
it will return as a response Set-Cookie and I will not be able to know on that request information I need but on the next one
Toyger
headers work fine
middleware:
page:
middleware:
import { NextResponse } from 'next/server'
export function middleware(request) {
const headers = new Headers(request.headers);
headers.set('middlewareSet', 'mydata');
const resp = NextResponse.next({
request: {
headers
}
});
return resp;
}
export const config = {
matcher: '/((?!api|_next/static|_next/image|favicon.ico).*)',
}
page:
import { headers } from 'next/headers'
export default function Page() {
const headersList = headers()
const middlewareSet = headersList.get('middlewareSet')
console.log(middlewareSet)
return <div>111</div>;
}