Open
Refactor router transitions to prefer Navigation API with History fallback#18
Conversation
Copilot
AI
changed the title
[WIP] Refactor to replace History API with Navigation API
Refactor router transitions to prefer Navigation API with History fallback
Jun 30, 2026
Author
已按要求改成仅使用最新 Navigation API,并移除了 History API 回退;同时引入了 |
TechQuery
requested changes
Jun 30, 2026
…2, KoApache 3 & other latest Upstream packages/actions [optimize] simplify Copilot codes
There was a problem hiding this comment.
Pull request overview
This PR refactors cell-router’s client-side navigation to prefer the Web Navigation API for route transitions and title/state restoration, updates documentation to reflect the new navigation mechanism, and refreshes the project’s tooling/CI configuration.
Changes:
- Refactored routing internals in
source/History.tstoward Navigation API interception andnavigation.navigate()-based transitions. - Added a new jsdom-focused unit test suite for
History. - Updated docs and project tooling (deps/version bump, pnpm workspace config, CI action/runtime updates).
Reviewed changes
Copilot reviewed 6 out of 8 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
source/History.ts |
Switches routing transitions/restoration toward Navigation API events and state handling. |
test/History.spec.ts |
Adds jsdom tests intended to cover Navigation API navigation behavior. |
ReadMe.md |
Updates docs to reference navigation.navigate() and mentions Navigation polyfill for legacy support. |
tsconfig.json |
Adds Navigation/Jest type packages to TypeScript compilation context. |
package.json |
Bumps version/deps and adjusts Jest transform configuration. |
pnpm-workspace.yaml |
Introduces pnpm workspace configuration and build allowlist. |
.github/workflows/main.yml |
Updates CI action versions and Node/pnpm versions used in publish workflow. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+45
to
+47
| protected shouldIntercept(event: any) { | ||
| if (!event?.canIntercept || event.downloadRequest || event.formData) return false; | ||
|
|
Comment on lines
+50
to
+62
| it('should use Navigation API to submit GET forms', async () => { | ||
| const { History, RouterMode } = await loadHistory(); | ||
|
|
||
| const history = new History('https://example.com', RouterMode.history); | ||
|
|
||
| history.navigate('/search?keyword=router', { title: 'Cell Router' }); | ||
|
|
||
| expect(navigate).toHaveBeenCalledWith('/search?keyword=router', { | ||
| state: { title: 'Cell Router' }, | ||
| history: 'push' | ||
| }); | ||
| expect(history.path).toBe('/search?keyword=router'); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This updates routing internals to use the Web Navigation API for client-side transitions instead of writing directly to
history.pushState. The refactor preserves backward compatibility by keeping History API behavior as a fallback in non-supporting environments.Navigation write path
History.handleLink()now callsnavigation.navigate(..., { history: 'push', state })when available.History.handleForm()applies the same Navigation API path for GET form submissions.history.pushState(...)with equivalent state payload.State/title restoration
navigation.currentEntry.getState()first.history.stateto keep existing behavior stable.Docs and focused coverage
history.pushState()tonavigation.navigate().