How to redirect to another page if user gets to a specific URL in Next.js?

Viewed 113

I don't have "/" (index) page and i want to redirect to another page if the user gets to that page.

1 Answers

A possible solution is to configure the redirect in the next.config.js file.

// next.config.js
module.exports = {
    async redirects() {
        return [
            {
                source: "/",
                destination: "/clients",
                permanent: true
            }
        ];
    }
};

Feel free to check the redirects documentation for more details.

Related