0

Please note that this question is not a duplicate of this one

I want to make pagination for my app. For example, the url for pages 2-10 should look like this: /products/2.

However, when the page is 1, I don't want to show the page number, i.e. the url should look like this: /products.

I also don't want to add locale into my url.

I'm using the pages directory.

  • You should consider using URLs in a best practice way. [This resource](https://developers.google.com/search/docs/specialty/ecommerce/pagination-and-incremental-page-loading#use-urls-correctly) and [this answer](https://stackoverflow.com/questions/50071884/pagination-with-url-path-or-the-query-parameters) (although python) is related. – Randy Casburn Feb 01 '23 at 05:15
  • the problem with this practice is that in Next.js, `getStaticProps` cannot read the stuff after the question mark. – BurgerBurglar Feb 01 '23 at 15:54
  • Right - so don't use `getStaticProps` - use `getInitialProps` to get the first page and then use the router to determine the next page. The `getInitialProps` will fetch the next page of data. Your handler (paginationHandler or something) will establish the current and previous pages (integer counters) and then route to the `next` page. You can pull the query parameters using the Router. – Randy Casburn Feb 01 '23 at 16:53
  • But `getInitialProps` isn't static. I want to build the HTML on build. – BurgerBurglar Feb 01 '23 at 16:59
  • OK. Keep hacking away at it to get it your way. But anyway, `getinitialProps` runs server side on the initial page load - it acts almost the same way as `getStaticProps`, but it achieves your goal - where `getStaticProps` will not. I think you'll find (or already have but not yet ready to accept) that you cannot have it both ways. – Randy Casburn Feb 01 '23 at 17:34
  • `getStaticProps` runs at build time, not at page load time. – BurgerBurglar Feb 01 '23 at 18:02
  • This sounds like an [XY Problem](https://xyproblem.info) - you've failed to clearly identify the problem, you've provided no code and your only goal seems to be to use dynamic data at build time (without regard to the consequences of doing so). Good luck to you. – Randy Casburn Feb 01 '23 at 20:37

0 Answers0