next.js - Nextjs using multiple parameters per slug
问题描述
export async function getStaticPaths() {
const posts = getPagesToRender();
const postPaths = posts.map((post, i) => {
return {
params: { page: post[1].replace(".md", ""), pageId: post[0] }
}
})
return {
paths: postPaths,
fallback: false
}
}
File names are like this: [1]page1.md
I pass it to getStaticPaths as
page: post[1].replace(".md", ""), pageId: post[0]
So they are like page: page1 pageId: 1
But It does not work because nextjs only expects 1 parameter. So I can only send the page parameter as nextjs ignores the second. Solution is to use 2 url slugs like this : [pageId]/[page]
But I don't want to pollute the url if possible.
Can you send 2 parameters from 1 slug?
解决方案
不,您应该使用[...slug].js
而不是[slug].js
. 这使参数成为一个数组!
推荐阅读
- python - 如何使用 python 获得显着性测试(例如 p 值)?
- php - 将一个数组值存储在php中的另一个对象数组中
- javascript - 使用 HERE MAP API 作为航点动态传递经度/纬度
- rest - okta 与 spring mvc rest api oauth2 集成
- java - 休眠加速插入
- java - ReflectionUtils 如何替换已弃用的方法?
- r - R 测量距海岸线的距离
- javascript - 你能做 .prev() 减去一个数字吗
- sql - 执行百分比时除以零错误(带有日期参数的未连接表的除数)
- python - python中的自定义日期格式解析