Skip to content

Instantly share code, notes, and snippets.

@6TELOIV
Created December 9, 2024 17:07
Show Gist options
  • Save 6TELOIV/fbe8938a32bb33fedc9dd88ddffb0bd8 to your computer and use it in GitHub Desktop.
Save 6TELOIV/fbe8938a32bb33fedc9dd88ddffb0bd8 to your computer and use it in GitHub Desktop.
Modal on top of route NextJS
/* app/@modal/default.tsx */
export default function Default() {
return null
}
/* app/@modal/modal/page.tsx */
export default function Modal() {
return (
<div>
<h2>Modal</h2>
<p>This is a modal</p>
</div>
)
}
/* app/layout.tsx */
export default function TestLayout({
children,
modal,
}: {
children: React.ReactNode
modal: React.ReactNode
}) {
return (
<html>
<body>
<div>
<h1>Test Layout</h1>
{children}
{modal}
</div>
</body>
</html>
)
}
/* app/page.tsx and app/modal/page.tsx */
import WorkRequestPage from '@/components/work-request-page'
export default WorkRequestPage
/* components/work-request-page.tsx */
export default function WorkRequestPage() {
return (
<div>
<h2>Work Request Page</h2>
<p>This is a the work requests page</p>
<a href="/modal">Open Modal</a>
</div>
)
}
@6TELOIV
Copy link
Author

6TELOIV commented Dec 9, 2024

File structure:

app/
├─ @modal/
│  ├─ modal/
│  │  ├─ page.tsx
│  ├─ default.tsx
├─ modal/
│  ├─ page.tsx
├─ page.tsx
components/
├─ work-request-page.tsx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment