Skip to content
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

Ensure selected segment is the value of dynamic routes #38644

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 7 additions & 5 deletions packages/next/client/components/hooks-client.ts
Expand Up @@ -16,13 +16,13 @@ export function useSearchParams() {
return useContext(QueryContext)
}

export function useSearchParam(key: string) {
export function useSearchParam(key: string): string | string[] {
const params = useContext(QueryContext)
return params[key]
}

// TODO-APP: Move the other router context over to this one
export function useRouter() {
export function useRouter(): import('../../shared/lib/app-router-context').AppRouterInstance {
return useContext(AppRouterContext)
}

Expand All @@ -31,7 +31,7 @@ export function useRouter() {
// return useContext(ParamsContext)
// }

export function usePathname() {
export function usePathname(): string {
return useContext(PathnameContext)
}

Expand All @@ -42,8 +42,10 @@ export function usePathname() {

export function useSelectedLayoutSegment(
parallelRouteKey: string = 'children'
) {
): string {
const { tree } = useContext(AppTreeContext)

return tree[1][parallelRouteKey][0]
const segment = tree[1][parallelRouteKey][0]

return Array.isArray(segment) ? segment[1] : segment
}