Unverified Commit e06983bf authored by Tim Neutkens's avatar Tim Neutkens Committed by GitHub

Ensure selected segment is the value of dynamic routes (#38644)

parent b1bb3d94
...@@ -16,13 +16,13 @@ export function useSearchParams() { ...@@ -16,13 +16,13 @@ export function useSearchParams() {
return useContext(QueryContext) return useContext(QueryContext)
} }
export function useSearchParam(key: string) { export function useSearchParam(key: string): string | string[] {
const params = useContext(QueryContext) const params = useContext(QueryContext)
return params[key] return params[key]
} }
// TODO-APP: Move the other router context over to this one // 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) return useContext(AppRouterContext)
} }
...@@ -31,7 +31,7 @@ export function useRouter() { ...@@ -31,7 +31,7 @@ export function useRouter() {
// return useContext(ParamsContext) // return useContext(ParamsContext)
// } // }
export function usePathname() { export function usePathname(): string {
return useContext(PathnameContext) return useContext(PathnameContext)
} }
...@@ -42,8 +42,10 @@ export function usePathname() { ...@@ -42,8 +42,10 @@ export function usePathname() {
export function useSelectedLayoutSegment( export function useSelectedLayoutSegment(
parallelRouteKey: string = 'children' parallelRouteKey: string = 'children'
) { ): string {
const { tree } = useContext(AppTreeContext) const { tree } = useContext(AppTreeContext)
return tree[1][parallelRouteKey][0] const segment = tree[1][parallelRouteKey][0]
return Array.isArray(segment) ? segment[1] : segment
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment