NextJs :pid 路由
NextJs :pid routes
有人知道什么是 exportPathMap: (next.config.js) 用于具有 :pid 的路径的 NextJS 吗?
我的 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: '' } },
问题是我的任务是创建一个看起来像这样的页面
/messages/925255252
而不是使用 /message?id=9252552252&t=foo
等查询参数的页面
现在在构建和导出时出现此错误
Cannot find module for page: /messages/:pid
文件。
pages > messages > index.js (/messages), [pid].js (messages/:id)
PS。
不使用SSR,渲染是客户端!
PPS。
在本地主机上一切正常,需要在生产中工作。
从 next.js 的范围 chat 来看,您想要实现的目标是不可能的:
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
因此您必须生成所有可能的页面(在您的情况下您需要所有可能的消息 ID),example 获取您的数据库。
或者切换到 SSR 并在服务器端处理您的请求。
有人知道什么是 exportPathMap: (next.config.js) 用于具有 :pid 的路径的 NextJS 吗?
我的 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: '' } },
问题是我的任务是创建一个看起来像这样的页面 /messages/925255252 而不是使用 /message?id=9252552252&t=foo
等查询参数的页面现在在构建和导出时出现此错误
Cannot find module for page: /messages/:pid
文件。
pages > messages > index.js (/messages), [pid].js (messages/:id)
PS。 不使用SSR,渲染是客户端!
PPS。 在本地主机上一切正常,需要在生产中工作。
从 next.js 的范围 chat 来看,您想要实现的目标是不可能的:
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
因此您必须生成所有可能的页面(在您的情况下您需要所有可能的消息 ID),example 获取您的数据库。
或者切换到 SSR 并在服务器端处理您的请求。