-
-
Notifications
You must be signed in to change notification settings - Fork 16
[replaceWithToast] is required #41
Description
redirectWithToast uses history.pushState, which causes the redirected URL to be added to the browser history. However, in some cases, we need to use history.replaceState instead while redirecting.
Example use case:
Let's say we have a products page at /products. We open the /products/new URL to add a new product. When the product is successfully created, we redirect to /products/{product_id}. However, in this case, pressing the back button on the product page brings the user back to /products/new, which is not desirable. Or think of I deleted /products/{product_id} and redirected to /products, now back navigation will bring me to a non-existing product.
If we try to solve this by returning jsonWithToast and then navigating manually using navigate('...', { replace: true }), we encounter duplicated toasts because the page navigates to the new URL very shortly after the toast cookie is flashed.
Proposal:
I would like to propose creating a replaceWithToast utility, which works exactly the same as redirectWithToast, but uses replace instead of redirect.
Note: I still use remix-toast@1.2.0 because some of our dependencies doesn't allow my switch to react-router@7. So I would be appreciated if you could also implement this feature for remix-toast@1.2.0 which is still the latest stable version for "remix" users.