Refactor routing to use useNavigate and fix redirect paths #99
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Title
Refactor Routing to Use useNavigate and Fix Redirect Paths
Description
This pull request refactors the routing implementation in the Cart component to use the useNavigate hook from react-router-dom instead of the deprecated history object. The changes address issues with relative redirect paths and ensure consistency with the current routing practices.
Changes Made:
Replaced history.push with useNavigate in the Cart component.
Updated redirect path in checkoutHandler to use an absolute path (/login?redirect=/shipping) to avoid issues with relative paths.
Why This Change?
The useNavigate hook is the recommended approach for handling navigation in React Router v6 and later. The previous use of history.push was not only outdated but also caused incorrect redirect paths due to relative path handling.
Related Issues:
Issue #98 : Fix incorrect redirect paths in the cart component.
Testing:
Verified that navigation to the login page with a redirect to the shipping page works as expected.
Ensured that the Cart component continues to function correctly with updated routing logic.
Screenshots/GIFs: