#change other path to default page

1 messages · Page 1 of 1 (latest)

obtuse cedar
#

i have / and /tickets. but / is empty and i want the /tickets page to be the deafalt page

static tuskBOT
#

Hi @obtuse cedar. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

To make /tickets the default page in your Next.js application, you can use the useRouter hook from next/router to programmatically redirect users from / to /tickets. Here's an example of how you can do this:

import { useEffect } from 'react'
import { useRouter } from 'next/router'
 
export default function HomePage() {
 const router = useRouter()
 
 useEffect(() => {
  router.replace('/tickets')
 }, [])
 
 return null
}

In this example, the HomePage component uses the useEffect hook to replace the current route with /tickets as soon as the component is mounted. This effectively redirects users visiting the / route to /tickets.

Please note that this is a client-side redirection, and the URL in the browser will change to reflect the /tickets route.

This code should be placed in the page.js file in your app directory, as per the Next.js routing conventions mentioned in the extracts (https://nextjs.org/docs/app/building-your-application/routing/defining-routes).

Remember, a page.js file is required to make a route segment publicly accessible. Pages are Server Components by default but can be set to a Client Component.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: