-
Notifications
You must be signed in to change notification settings - Fork 16
feat: support search parameters #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ismamz
wants to merge
5
commits into
main
Choose a base branch
from
feat/search-params
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
19d9517
feat: support search parameters
ismamz a02e740
feat: update demo page layout and navigation links
ismamz c9d98e0
feat: update back button label to include arrow
ismamz c66163c
feat: add SearchParamsHandler to manage path changes with search para…
ismamz 39540e3
feat: update searchParams type to support numeric page values
ismamz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -7,9 +7,10 @@ import { | |||||
| useMemo, | ||||||
| useRef, | ||||||
| useState, | ||||||
| Suspense, | ||||||
| } from "react"; | ||||||
| import delegate, { DelegateEvent } from "delegate-it"; | ||||||
| import { usePathname, useRouter } from "next/navigation"; | ||||||
| import { usePathname, useRouter, useSearchParams } from "next/navigation"; | ||||||
| import { NavigateOptions } from "next/dist/shared/lib/app-router-context.shared-runtime"; | ||||||
| import { isModifiedEvent } from "./utils"; | ||||||
|
|
||||||
|
|
@@ -55,10 +56,15 @@ export function TransitionRouter({ | |||||
| const pathname = usePathname(); | ||||||
|
|
||||||
| const [stage, setStage] = useState<Stage>("none"); | ||||||
| const [pathWithSearch, setPathWithSearch] = useState(() => pathname); | ||||||
|
|
||||||
| const leaveRef = useRef<(() => void) | void | null>(null); | ||||||
| const enterRef = useRef<(() => void) | void | null>(null); | ||||||
|
|
||||||
| const handlePathChange = useCallback((newPathWithSearch: string) => { | ||||||
| setPathWithSearch(newPathWithSearch); | ||||||
| }, []); | ||||||
|
|
||||||
| const navigate: NavigateProps = useCallback( | ||||||
| async (href, pathname, method = "push", options) => { | ||||||
| if (stage === "leaving") return Promise.resolve(); | ||||||
|
|
@@ -78,15 +84,19 @@ export function TransitionRouter({ | |||||
| const ignore = anchor?.getAttribute("data-transition-ignore"); | ||||||
|
|
||||||
| const url = href ? new URL(href, window.location.origin) : null; | ||||||
| const targetPathname = url?.pathname; | ||||||
| const currentUrl = new URL(window.location.href); | ||||||
|
|
||||||
| const isSamePage = | ||||||
| url?.pathname === currentUrl.pathname && | ||||||
| url?.search === currentUrl.search; | ||||||
|
|
||||||
| if ( | ||||||
| !ignore && | ||||||
| href?.startsWith("/") && | ||||||
| targetPathname !== pathname && | ||||||
| !isSamePage && | ||||||
| anchor.target !== "_blank" && | ||||||
| !isModifiedEvent(event) && | ||||||
| !(href.includes("#") && targetPathname === pathname) | ||||||
| !(href.includes("#") && url?.pathname === pathname) | ||||||
| ) { | ||||||
| event.preventDefault(); | ||||||
| navigate(href, pathname); | ||||||
|
|
@@ -128,7 +138,7 @@ export function TransitionRouter({ | |||||
| setStage("entering"); | ||||||
| } | ||||||
| }; | ||||||
| }, [stage, pathname]); | ||||||
| }, [stage, pathWithSearch]); | ||||||
ismamz marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| }, [stage, pathWithSearch]); | |
| }, [stage, pathname]); |
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.
Uh oh!
There was an error while loading. Please reload this page.