Alex
Alex

Reputation: 1420

NextJs :pid routes

Does anybody know what is the exportPathMap: (next.config.js) for NextJS of a path that has a :pid?

My expotPathMap

  exportPathMap: async (defaultPathMap) => {
  return {
  '/': { page: '/', query: {} },
  '/login': { page: '/login', query: { verifySuccess: null } },
  '/signup': { page: '/signup', query: {} },
  '/search': { page: '/search', query: { s: '', category: '' } },
  '/messages': { page: '/messages', query: { t: '' } },
  '/messages/:pid': { page: '/messages/:pid', query: { t: '' } },

Issue is that I was tasked to create a page that would look like /messages/925255252 instead of a page that uses a query param like /message?id=9252552252&t=foo

Now when building & exporting I am getting this error

Cannot find module for page: /messages/:pid

The files.

pages > messages > index.js (/messages), [pid].js (messages/:id)

PS. Not using SSR, rendering is client sided!

PPS. All is fine on localhost, needs to work in production.

Upvotes: 0

Views: 1039

Answers (1)

Nico
Nico

Reputation: 7256

What you are trying to achieve is not possible, from the spectrum chat of next.js :

You have to return a mapping of every possible route, dynamic matching wouldn't have any effect even if we did support it, how would you know what /show/:id is going to be when exporting? We have to know exactly what is going to be exported at export time

So you have to generate all possibile pages (in your case you need all possible messages ids), example fetching your database.
Or switch to SSR and handle your requests server side.

Upvotes: 1

Related Questions