N
Nuxt5mo ago
Miguel

Same page component for 2 routes?

I have a /news route, with a News component, that fetches and renders news items from my cms. Now I also have /news/category/[category] route, which shows news for a certain category. Now the code is almost identical to the normal news route/component, I only need to pass a slug if it's set in the url. Can I reuse this component to serve both routes?
/news (route 1)
/news/category/[category] (route 2)
/news (route 1)
/news/category/[category] (route 2)
1 Reply
oneeach
oneeach5mo ago
Yes, you may need to update your component to check for a prop to see if the category is specified https://nuxt.com/docs/guide/directory-structure/components https://vuejs.org/guide/essentials/component-basics.html#passing-props <News :category="'category" /> inside component: const props = defineProps(['category'])
Want results from more Discord servers?
Add your server