I use nextjs 12.3.4 , I use GetServerSideProps function , get info from server .
how I can get the url of client?
I use nextjs 12.3.4 , I use GetServerSideProps function , get info from server .
how I can get the url of client?
Not really sure what you mean by that.
You can get route info from the router object
I use GetServerSideProps
function, it is server side rendering. I can not use useRouter
export const getServerSideProps: GetServerSideProps<
{ currentUrl: string }
> = async context => {
const { headers, url } = context.req;
const protocol =headers["x-forwarded-proto"] || "http";
const {host} = headers;
const currentUrl = `${protocol}:${host}${url}`;
return {
props: {
currentUrl,
},
};
};
const Invite: FC<
InferGetServerSidePropsType<typeof getServerSideProps>
> = ({ currentUrl }) => {
console.log(currentUrl )
};
return (...)
}
I get url for req.header
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.