2

My react app does not have any content to show for "/" root path.

Instead I want always to show "/projects" path when user enters "https://awesomesite.com" ("/") root page.

Is this correct solution for this use case or should I manage to do it differently?

// main.tsx
root.render(<RouterProvider router={router} />)
// router.tsx
const router = createBrowserRouter([
    {
        path: '/',
        element: <App />,
        errorElement: <ErrorPage />,
        children: [
            {
                index: true,
                element: <Navigate replace to='/projects' />,
            },
            {
                path: '/projects',
                element: <ProjectsPage />,
            },
        ],
    },
])
// App.tsx
export default function App() {
    return (
        <div className='flex h-screen w-screen'>
            <Sidebar />
            <div className='flex grow flex-col'>
                <Outlet />
            </div>
        </div>
}
magino
  • 109
  • 9

0 Answers0