vercel / next.js

The React Framework
https://nextjs.org
MIT License
125.5k stars 26.81k forks source link

output export ssg generation for dynamic even with generateStaticParams id value is comming as %5Bslug%5D so page is not generated in build #65560

Open veract-dev opened 4 months ago

veract-dev commented 4 months ago

Link to the code that reproduces this issue

https://github.com/veract-dev/prahars.git

To Reproduce

nextjs.config


/** @type {import('next').NextConfig} */
const nextConfig = {

    output: 'export',
    trailingSlash: true,

    images: {
        unoptimized: true,
    },

}

module.exports = nextConfig

blog/[slug]/page.tsx


export async function generateStaticParams() {
    const blogs = (await getAllBlogs()).data;
    if (blogs && blogs.length > 0) {
        let final = blogs.map((blog: BlogI) => ({
            slug: blog.id
        }))

        return final;
    } else {
        return [];

    }

export default async function Page({ params }: any) {
    let { slug } = params
    console.log("id before", slug)
    let data = (await getBlog(slug)).data;
    let blog = data as BlogI ?? null;

    return (
        <div>
            <div className="desktopBlogInnerPage">
                <div className="innerpage_title">{blog?.title}</div>

                <div className="image-container img"><Image src={blog.thumbnail} alt="Description of the image" width={1000} height={667} /></div>
                <div className="innerpage_content_padding">
                    {blog.content}
                </div>
            </div>

            <div className="mobileBlogInnerPage">
                <div className="innerpage_title">{blog.title}</div>
                <div className="image-container_mobile">
                    <div className="image-container img_mobile"><Image src={blog.thumbnail} alt="Description of the image" width={1000} height={667} /></div>
                </div>
                {/* <div style={{display: "flex", justifyContent:"center", backgroundSize:'contain', paddingTop:"40px"}}><div className="background_img"></div></div> */}
                <div className="innerpage_content_padding">
                    {blog.content}
                </div>
            </div>
        </div>
    )

}

Current vs. Expected behavior

Current behavior in npm build files are not generated for id with value Expected behavior to build files and generate

Provide environment information

Operating System:
  Platform: windows
  Arch: x64
  Version: 12
Binaries:
  Node: 20.9.0
  npm: 9.4.0
  pnpm: N/A
Relevant packages:
  next: 14.2.3
  eslint-config-next: N/A
  react: ^18
  react-dom: ^18

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

updated code is in master branch

jiannx commented 4 months ago

I have the same problem , I think it's because next will encodeURIComponent the data returned by generateStaticParams, and then passing to the the component's props.params,which results props.params can not match the data

guybinya commented 2 months ago

Same here, did you find a solution?

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!