1

i'm trying to learn how dynamic routes work with NextJS and the thing is that in localhost (npm run dev) works fine, but as soon as I push it to production in Netlify I get 404 error. Static pages are working, it just happends with dynamic routes. Here is an example of the code I have (is just a simple, static json to test how it works):

function ArticleListByCategory({articles}){
    
return(
    <>
    <h1>{JSON.stringify(articles)}</h1>
    </>
)
}
export default ArticleListByCategory

export async function getServerSideProps(context){
    const {params} = context
    const {category} = params
    return {
        props:{
            articles:{
                "news":[
                    {
                        "name":"article1",
                        "category":category
                    }
                ]
            }
        }
    }
}

Thanks in advance

1 Answer 1

1

install@netlify/plugin-nextjs

add netlify.toml in your root directory

[build]
publish = ".next"

[[plugins]]
package = "@netlify/plugin-nextjs"

package.json

"next": "^12.1.0",
"react": "^18.2.0",

Here's a working example Nextjs SSR with netlify. https://stackblitz.com/edit/nextjs-9rssk1

Live preview https://capable-medovik-a6ec0b.netlify.app/

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.