Route only works on hard refresh - am i working against the framework? #10327
-
Hi - i'm new to Remix but i really like it so far! ScenarioIn my application i have a route SolutionSo my solution have been to define a import { LoaderFunctionArgs } from "@remix-run/node";
import { isRouteErrorResponse, json, Outlet, useLoaderData, useNavigate, useRouteError } from "@remix-run/react";
import { useEffect } from "react";
export const loader = async () => {
const deliveries = await getAllDeliveries(); // A huge object that has a ton of information needed below, but also informs me about which delivery types exist.
return json({ deliveries });
}
export default function DeliveryPage() {
const { deliveries } = useLoaderData<typeof loader>()
const navigate = useNavigate();
// Navigate to route: deliveries.$type.tsx
useEffect(() => {
const deliveryTypes = getUniqueDeliveryTypes(deliveries);
navigate(`/deliveries/${deliveryTypes[0]}`, { "replace": true });
}
}, []);
return <>
<h1>Delivery Page!</h1>
{/* Pass deliveries to be consumed by children to avoid re-fetching it */}
<Outlet context={deliveries} />
</>
} The route export default function DeliveryTypes {
return <h1>Hello from delivery types!</h1>
} Problem with solutionThe above actually navigates to the route in the browser, changing the url to: { status: 404, statusText: "Not Found", internal: true, data: 'Error: No route matches URL "/deliveries/bicycle"', error: Error } But if i do a hard-refresh the page loads just fine! So i do not know if i'm doing something wrong or i'm experiencing a bug. Best, |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 9 replies
-
Remaining in the context of the solution you try: No navigate and Outlet context needed then. Bear in mind, Though if I was you, I would rather look forward to solve the complexity of |
Beta Was this translation helpful? Give feedback.
-
It will be easier to help you if you provide a repro via https://remix.new. |
Beta Was this translation helpful? Give feedback.
-
The 404 comes probably due to It is important, before navigating to reload the page fully as shown in the video, because then the route is "undiscovered" again: |
Beta Was this translation helpful? Give feedback.
The 404 comes probably due to
v3_lazyRouteDiscovery
Reproduction stackblitz
It is important, before navigating to reload the page fully as shown in the video, because then the route is "undiscovered" again:
10327.webm