#Remix v2 routing - layout or index?

1 messages · Page 1 of 1 (latest)

twilit remnant
#

Hello I'm new to remix and I tried reading the official docs for route file naming and asking chatGPT about routing but I just don't understand it.

This is my routing:

root.tsx
routes/
  _public.tsx <-- i want this to be layout for every route under _public/
  _public/ 
    index.tsx <-- should map to '/'
    login.tsx <-- should map to '/login'

However this is the error I'm getting in the console. I assume this is because it thinks _public.tsx is a route rather than a layout but then how do i make the _public.tsx to act as a layout?

⚠️ Route ID Collision: "routes/_public"

The following routes all define the same Route ID, only the first one will be used

🟢 routes/_public/index.tsx
⭕️️ routes/_public.tsx

EDIT: This is my _public.tsx if it's relevant

import { Outlet } from '@remix-run/react'
import { PublicNavbar } from '~/components/public-navbar'

export default function Layout() {
  return (
    <>
      <PublicNavbar />
      <div className='px-6 py-8 max-w-5xl mx-auto'>
        <Outlet />
      </div>
    </>
  )
}
fallen heath
#

In remix v2 routing route segment is separate by . in file name so you will have flat route folder
so in your case

_public.tsx -> layout
_public._index.tsx -> /
_public.login.tsx -> /login 

the _ is required for index file