is there a way for accessing parent routes slugs?
Answered
Common Moorhen posted this in #help-forum
Common MoorhenOP
i have a path
/projects/[id] and i want to access the [id] in the path /projects/[id]/settings. is there a way for doing it with next js routing?8 Replies
Transvaal lion
Yea I have pages/[region]/crafting/[professionName]/[expansionName]-profit-calculator.tsx and it looks like this for example
export const getStaticProps: GetStaticProps = async ({ params }) => {
const { professionName, expansionName, region } = params as {
professionName: string;
expansionName: string;
region: string;
};you can do the same if it's not an ISR page
Common MoorhenOP
does that work on the app* pages too?
srry, dyslexia hashdfhas
Transvaal lion
either something like this serverside, or via useRouter router.query.id like shown here https://nextjs.org/docs/pages/building-your-application/routing/dynamic-routes
export const getServerSideProps: GetServerSideProps = async (context) => {
const { id } = context.params;
return {
props: {
// Pass the `id` as a prop to the page component
id,
},
};
};Common MoorhenOP
im using the app router
Common MoorhenOP
it looks like it works
Answer
Common MoorhenOP
thank you for your help!