-
I setup a global message on an outlet container that should show flash message only once. On This is working as expected but when going back to route a I still see the message. here is a link to a working example - https://codesandbox.io/s/trusting-dhawan-cnfkl3?file=/app/routes/container/a.tsx |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Remix is actually working as designed. The issue is that you're displaying the flash message in a common parent route. When route The rule of thumb is don't render anything in parent routes that you expect to change when simply navigating in common child routes. You need something that will trigger the parent to re-render. In this sample, I'm using export default function () {
const { globalMessage } = useLoaderData()
const location = useLocation()
const [savedLocation] = useState(location.key)
return (
<div>
{location.key === savedLocation && <div>{globalMessage}</div>}
<Outlet />
</div>
)
} https://codesandbox.io/s/friendly-benji-1or7jr?file=/app/routes/container.tsx |
Beta Was this translation helpful? Give feedback.
Remix is actually working as designed. The issue is that you're displaying the flash message in a common parent route.
When route
a
submits and redirects tob
, Remix will revalidate the loaders. This will fetch fromcontainer
route and render the global message. When you navigate fromb
back toa
, thecontainer
route is still a common parent route, so Remix will not refetch the data, nor will it re-render.The rule of thumb is don't render anything in parent routes that you expect to change when simply navigating in common child routes.
You need something that will trigger the parent to re-render.
In this sample, I'm using
useLocation
to check every time the route changes, and only displa…