Skip to content

Commit

Permalink
Ensure selected segment is the value of dynamic routes (#38644)
Browse files Browse the repository at this point in the history
  • Loading branch information
timneutkens committed Jul 14, 2022
1 parent b1bb3d9 commit e06983b
Showing 1 changed file with 7 additions and 5 deletions.
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
}

0 comments on commit e06983b

Please sign in to comment.