for context I am in a folder in pages in a file named [id].jsx. How do I get getServerSide props to return the name of the page ex /page/id123 I want it to return id123.
import Link from 'next/link';
import React from "react";
export default function Global() {
console.log(context)
const address = useAddress();
const disconnectWallet = useDisconnect();
while (address) {
return (
<Link href="/">
<a className="absolute pt-1 text-xl font-semibold transform -translate-x-1/2 top-1/2 left-1/2"> Click Here To Login</a>
</Link>
</>
);
}
export function getServerSideProps(context) {
console.log("context: ", context.params)
return {
props: {context},
}
}
Since your dynamic page is called [id].jsx, you can access that id in your getServerSideProps with: context.params.id.
export function getServerSideProps(context) {
return {
props: {id: context.params.id},
}
}
Then in your component:
export default function Global({ id }) {
console.log(id);
...
}
You can also access it using router object that comes from Next.js' useRouter hook:
export default function Global() {
const router = useRouter();
const { id } = router.query;
console.log(id);
...
}
You can use ctx.resolvedUrl. It will either return what you want or you'll be able parse the needed part out