K
K
Kipsy2021-11-01 22:21:01
React
Kipsy, 2021-11-01 22:21:01

Is it possible to make dynamic routing in next with static export?

Good evening. Tell me how can I make dynamic routing with static export in next?
Now I have a MainNews component with all the news and links to the news in more detail.
Links lead to a dynamic page along the path /news/[current].js its path is generated from the name of the news in ${encodeURIComponent(data.fields.slug)}

const MainNews = () => {
    useEffect(() => {
        //...code
    }, [])
    return (
        <div className="main__news-items">
            {data.map((data, idx) => (
                <Link key={idx} href={`/news/${encodeURIComponent(data.fields.slug)}`}>
                    <a>
                        читать новость
                    </a>
                </Link>
            ))}
        </div>
    );
};

Now I get it dynamically using the server through
export const getStaticPaths: GetStaticPaths = async () => {
    const newsEntries = await client.getEntries({
        content_type: 'news',
        select: 'fields.slug'
    })
    return {
        paths: newsEntries.items.map((item:any) => {
            // console.log(projects)
            return {
                params: {
                    news: item?.fields?.slug
                }
            }
        }),
        fallback:false
    }
}

export const getStaticProps: GetStaticProps = async ({params}) => {
    const slug = params!.news!;

    const newsEntries = await client.getEntries({
        content_type: 'projects',
        limit: 1,
        'fields.slug': slug
    })
    const [news] = newsEntries.items

    return {
        props: {
            news
        }
    }
}

But what I need is that it would also be possible to dynamically receive a page with the current news, but with a static next export without a server. To upload to regular hosting. Is it possible to do so? Or dynamic routes only work with the server?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question