Multiple index routes #1073
-
Hi there 👋 I'm looking into Remix for an upcoming web application. Playing around with the tutorial and reading the docs it looks like the router isn't very flexible. I need to implement multiple index routes (or root routes |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Getting me defensive over here with "not very flexible", the router is incredibly flexible! It just doesn't deal with hostnames, only pathnames. But you can change your UI based the host by sending the information down from your loader: export function loader({ request }) {
let url = new URL(request.url);
return { hostname: url.hostname }
}
export default function Index() {
let { hostname } = useLoaderData();
return hostname === "cheese" ? <Cheese /> : <Beef />
} |
Beta Was this translation helpful? Give feedback.
-
Thanks for taking the time to answer this Ryan. I sort of figured I could do something like this but what I'm worried about is the chunk size. Since these are runtime checks, there is no way for Remix to do any sort of "smart" code splitting per "index route". I would end up with all of them in a single bundle, right 🤔? |
Beta Was this translation helpful? Give feedback.
-
If only hostname determines the index route, maybe you can use remix.config.js to define custom routes based on host? Pass host at build time, then use different file to handle it. |
Beta Was this translation helpful? Give feedback.
Getting me defensive over here with "not very flexible", the router is incredibly flexible! It just doesn't deal with hostnames, only pathnames.
But you can change your UI based the host by sending the information down from your loader: