Add replace support#96
Conversation
There was a problem hiding this comment.
Pull request overview
Adds “replace” navigation semantics to the sgRouter so callers can replace the current history entry (and corresponding view) rather than pushing a new one, along with test coverage for the new option.
Changes:
- Introduce
{ replace: true }option handling inRouter._navigateTo, including newfromReplaceStatenavigation-state flag. - Update history stack logic in
showViewto replace the last entry whenfromReplaceStateis set. - Add a new
describe("replace")test block validating history behavior, view destruction, mid-stack replacement, event emission, and named-route support.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| src/components/Router.bs | Implements replace option and updates view/history management via new fromReplaceState flag. |
| src/source/router.spec.bs | Adds tests covering the new replace navigation behavior. |
Comments suppressed due to low confidence (1)
src/components/Router.bs:868
- The
fromReplaceStatehistory-update branch bypasses theclearStackOnResolvehistory reset logic. If a route hasclearStackOnResolve=trueand navigation is invoked with{ replace: true }, views can be cleared but__router_historyStackwon’t be, leaving stale entries and breakinggoBack/popTo. Consider makingclearStackOnResolveoverride/ignorereplace, or clearing the stack before applying replace semantics.
if context.view.route.routeConfig.clearStackOnResolve then
m.__router_historyStack = []
end if
if context.view.route.navigationState.fromPushState then
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <[email protected]>
…outer into 95-add-replace-support
|
Hey there! I just built a new temporary npm package based on 3eb5079. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316150414.tgz |
There was a problem hiding this comment.
Pull request overview
Adds “replace navigation” support to the sgRouter so callers can navigate forward while replacing the current history entry (similar to history.replaceState), and introduces tests to validate replace semantics across history/view-stack behavior.
Changes:
- Add
replaceoption handling to Router navigation, including newfromReplaceStatenavigation state flag and history-stack replacement logic. - Ensure replace closes the currently active view (when not
clearStackOnResolve) and updates router state events consistently. - Add a new
replacetest suite covering history replacement, view destruction, named routes, and interaction withclearStackOnResolve.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/components/Router.bs |
Implements replace option, sets fromReplaceState, adjusts view removal behavior, and replaces the last history entry on navigation. |
src/source/interfaces.bs |
Extends NavigationState with fromReplaceState to represent replace-style forward navigation. |
src/source/router.spec.bs |
Adds coverage for replace navigation behavior (history, view stack, events, named routes, clear-stack precedence). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Hey there! I just built a new temporary npm package based on c004f50. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316152424.tgz |
|
Hey there! I just built a new temporary npm package based on 705aa78. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316162539.tgz |
|
Hey there! I just built a new temporary npm package based on 003fd41. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316185622.tgz |
|
Hey there! I just built a new temporary npm package based on 2c957f1. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260316190233.tgz |
|
Hey there! I just built a new temporary npm package based on b9d78ce. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260317115805.tgz |
|
Hey there! I just built a new temporary npm package based on b9d78ce. You can download it here or install it by running the following command: npm install https://github.com/rokucommunity/sgRouter/releases/download/v0.0.0-packages/rokucommunity-sgrouter-0.1.2-95-add-replace-support.20260317120038.tgz |
| end if | ||
|
|
||
| viewsToRemoveOnResolve = [] | ||
| forceCloseViews = [] |
There was a problem hiding this comment.
Might need to rethink this? I think these might bypass the keepalive stuff, but probably shouldn't.
| @@ -27,6 +27,7 @@ namespace sgRouter | |||
| interface NavigationState | |||
| fromPushState as Boolean ' normal forward navigation | |||
There was a problem hiding this comment.
Should likely set this as part of this PR too (since replace is equivalent to a .pop() and .push())
No description provided.