fix: implement proper browser back button navigation for SPA #188
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.
📝 Description
Fixes the back button navigation issue where clicking the browser's back button would exit the site instead of navigating to the previous step within the workout builder.
Problem
The workout builder uses Zustand for state management, which only stores state in memory. When users navigate through steps (Equipment → Muscles → Exercises), no browser history entries are created. This causes the back button to exit the application entirely instead of going to the previous step.
Solution
?step=1
,?step=2
,?step=3
popstate
event listener to handle back/forward button clicksChanges Made
Main Fix:
workout-builder.store.ts
to sync with browser historyupdateURL()
helper to push history statesgetStepFromURL()
to read initial state from URLpopstate
event listener for back/forward navigationsetStep
,nextStep
,prevStep
,loadFromSession
methodsAdditional Improvements:
useSignUp.ts
- replacedwindow.location.href
withrouter.push()
window.location.reload()
withrouter.refresh()
create-program-modal.tsx
add-session-modal.tsx
add-week-modal.tsx
Technical Details
pushState
,popstate
)window
before accessing browser APIs📋 Checklist
🗃️ Prisma Migrations (if applicable)
📸 Screenshots (if applicable)
Testing completed:
?step=1
,?step=2
,?step=3
/workout-builder?step=2
)🔗 Related Issues
Closes #80