reactjsnext.js

how to set default page in next js?


i am new in next.js, in next.js default page in index.js, i want to change its path as login , can anyone please help me how to do it ? right now i am using Router.push('/login'); but it is creating flickering issue, can anyone please help for this issue ?

import Head from 'next/head'
import styles from '../styles/Home.module.css'
import Router from 'next/router'
import React, { useEffect } from "react";
import { Redirect } from 'react-router';


export default function Home(props) {
  useEffect(() => {
    const { pathname } = Router
    if (pathname == '/') {
      Router.push('/login');
    }
  }, [props]);

  return ''
}

Solution

  • You can add redirects to your next.config.js like this:

    module.exports = {
      async redirects() {
        return [
          {
            source: '/about',
            destination: '/',
            permanent: true,
          },
        ]
      },
    }