-
Hello everyone, I've encountered a situation during my development with Remix and am seeking discussions and help. I have content in
In this setup, navigating to However, I'm looking for a way to achieve a slightly different routing effect:
My intention behind this design is to use a base layout for certain pages, which can be determined by the routing conventions based on file naming. Currently, if I have these two files in
Error message:
To achieve my goal, I considered passing a value through Thank you for your time and assistance. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
See this: #7296 |
Beta Was this translation helpful? Give feedback.
-
As the error said, an index route can't have child routes, this is because index is always a leaf route (the last one, in this case What you need is to create a pathless layout route that can have your shared layout.
I also like to name my global layout as
The reason I do this is because the layout name will be repeated a lot so I prefer to use a short name, |
Beta Was this translation helpful? Give feedback.
-
So the key insight from this discussion is that // app/routes/_.tsx
import { Outlet } from "@remix-run/react";
export default function Layout() {
return (
<>
{/* This is what used to be in _index.tsx */}
<div>Always visible content!</div>
<Outlet />
</>
);
}
// app/routes/_._index.tsx
export default function Index() {
// Empty component that just establishes "/" as a valid route
return null;
}
// app/routes/_.contact.tsx
export default function Contact() {
return <div>Additional content for the /contact route</div>;
} |
Beta Was this translation helpful? Give feedback.
As the error said, an index route can't have child routes, this is because index is always a leaf route (the last one, in this case
/
).What you need is to create a pathless layout route that can have your shared layout.
I also like to name my global layout as
_.tsx
so the folder structure would look like this: