Based on your new routing structure with /browse/[[...segments]], we can adjust the folder structure to accommodate both the browse page and the modal. Here's how you can lay out the folder structure:
app/
├── browse/
│ ├── [[...segments]]/
│ │ └── page.tsx
│ └── @modal/
│ └── (.)[[...segments]]/
│ └── page.tsx
└── layout.tsx
In this structure:
app/browse/[[...segments]]/page.tsx handles all your browse routes, including the media type and optional slug.
app/browse/@modal/(.)[[...segments]]/page.tsx is the intercepting route for the modal.
The (.) in the modal folder name indicates that this route should intercept its siblings, as mentioned in the Intercepting Routes documentation:
"You can use:
(.) to match segments on the same level"
This structure allows you to intercept the browse route and display it as a modal when needed.
Remember to update your root layout (app/layout.tsx) to handle the @modal slot:
export default function RootLayout({
children,
modal
}: {
children: React.ReactNode
modal: React.ReactNode
}) {
return (
<html>
<body>
{children}
{modal}
</body>
</html>
)
}
In your app/browse/[[...segments]]/page.tsx and app/browse/@modal/(.)[[...segments]]/page.tsx files, you'll need to handle the segments parameter, which will be an array of strings. You can use this to determine the media type and slug as needed.
For example:
export default function BrowsePage({ params }: { params: { segments?: string[] } }) {
const [mediaType, ...slugParts] = params.segments || [];
const slug = slugParts.join('/');
}