Nuno Azevedo
Nuno Azevedo

Reputation: 144

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

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

Upvotes: 2

Views: 611

Answers (1)

juliomalves
juliomalves

Reputation: 50268

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.

Upvotes: 3

Related Questions