-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Splat Route doesn't handle root index path. #5841
Comments
That is the intended behavior, Index Routes routes are a bit special, they share the same URL as their parent route and they render inside the On the other hand, Splat Routes are last resort for Remix to match if nothing else matches. Remix (React Router really) uses an algorithm that gives each route a rank, routes that rank higher will be given priority to handle a URL. When route X renders a
See this example, I tried to demonstrate how index and splat are matched https://stackblitz.com/edit/remix-issue-5841 |
@akamfoad I was asked to open this issue by a Remix team member, as this behavior doesn't match React Router's handling of the |
@rossipedia I see, I wasn't aware of that. |
This is fixed by #6130 and should be available once 1.16.0 is released |
🤖 Hello there, We just published version Thanks! |
I think we goofed by calling this an issue. I misunderstood in discord that the bug was "splat routes don't work unless a sibling index route is also defined". But rather, this issue is asking "why doesn't the splat route match the parent URL like an index route?" or "how do I create a root splat route". In current react router semantics:
Given that, I would not expect the remix splat route to match In React router, <Route path="/" element={<Root />}>
<Route path="*" element={<Splat />} />
</Route> You create that router tree in remix with these files: root.tsx
routes/$.tsx If you want the same handling for all routes, you'll need to also have a sibling index route by the splat route to match the parent route. root.tsx
routes/_index.tsx
routes/$.tsx We discussed internally what would happen if we change the root route to be a pathless route: <Route element={<Root />}>
<Route path="*" element={<Splat />} />
</Route> But this now causes There are times where I'd personally like my root.tsx to be able to handle all paths, or have a splat route handle everything that's not defined otherwise (including A couple deeper questions:
|
This change was reverted in #6222 |
fwiw I've worked on several apps (including a demo I'm building right now) where everything is intended to happen through a single route e.g. the it was surprising to me that there was no way to define a "everything goes through here" file maybe this could be a special opt-in format? |
for future googlers, this was my workaround, assuming you've got a file structure like this:
set up import RouteComponent from './_index';
export { loader } from './_index';
export default RouteComponent; |
With routes: async (defineRoutes) => {
return defineRoutes((route) => {
route("/", "everything.tsx", { id: "index" });
route("*", "everything.tsx", { id: "splat" });
});
}, |
oh dang! what version did that land in? I'll update my demo |
v0.1.0, file system routes are whack. |
What version of Remix are you using?
1.14.3
Are all your remix dependencies & dev-dependencies using the same version?
Steps to Reproduce
npx create-remix@latest
app/routes/index.tsx
toapp/routes/$.tsx
npm run dev
Expected Behavior
The default index route displays.
Actual Behavior
Nothing is shown.
See the behavior here
The text was updated successfully, but these errors were encountered: