Let's say I have a dynamic route in my application, with the name [id]
Typically, I use getServerSideProps
in the pages router to validate any properties passed to the route. It usually looks something like this:
export async function getServerSideProps(ctx: GetServerSidePropsContext) {
const { locale, query } = ctx
//Validate query id
const id = parseInt(query.id as string, 10)
if(isNaN(id)) {
return {
notFound: true
}
}
else {
//Include logic here to validate the id against the API or pass it as props to the client
}
}
I find this method useful for maintaining separation, but I'm unsure how to achieve similar results with the app router. The documentation is unclear to me on this matter.