1

I have a nextjs app with two pages, they have same design but both display different data, what is the best way to implement this idea with keeping the url path unique for each page.

3
  • 2
    Use dynamic paths. pages/[unique-slug].js. Depending on the value of unique-slug, you may then display relevant data. Docs for your reference
    – PsyGik
    Commented Aug 19, 2021 at 16:23
  • Thank you very much, Will i face any problems when directly create this file at pages dir, or should i make another directory for it ? Commented Aug 20, 2021 at 7:16
  • depends on how you want to structure things. I'd recommend pages/[unique-slug]/index.js so that if you want to introduce a new path under unique-slug/some-path, it's as simple as creating pages/[unique-slug]/some-path.js file.
    – PsyGik
    Commented Aug 20, 2021 at 12:11

1 Answer 1

1

after asking some friends about this issue the best answer i got (from my prospective) is to separate the repeated code at the two pages into a new directory which I named shared and a new component that has only one job to display the data passed to it from both pages.

Not the answer you're looking for? Browse other questions tagged or ask your own question.