diff --git a/packages/runtime/src/use-navigation-list.ts b/packages/runtime/src/use-navigation-list.ts index 5fa2d1c..634d476 100644 --- a/packages/runtime/src/use-navigation-list.ts +++ b/packages/runtime/src/use-navigation-list.ts @@ -23,10 +23,15 @@ function routeKeyToLabel(key: string) { * @param labelFactory optional. A function to create a label for a route. If not provided, every route will have the last part of * its key capitalized as its label. If the label factory returns undefined, the default rule for building labels is used. If it returns * null, the route is removed from the list. + * @param shouldMergeSearchParams optional. A function that takes a route key and returns a boolean indicating whether the search + * parameters (query string) from the current location should be merged into the route's URL. If the function returns `true`, the + * search parameters will be merged into the `href` of the route. If it returns `false` or is not provided, the search parameters + * will not be merged. * @returns the navigation list. */ export function useNavigationList( labelFactory?: (key: string, params: Record) => string | undefined | null, + shouldMergeSearchParams?: (key: string) => boolean ): NavigationItem[] { const [data, setData] = useState<{ route?: AnyRoute, params?: Record }>({ route: CitronNavigator.instance?.currentRoute, @@ -45,7 +50,11 @@ export function useNavigationList( ? result : [ ...result, - { key: route.$key, href: route.$link({}), label }, + { + key: route.$key, + href: route.$link({}, { mergeSearchParameters: shouldMergeSearchParams?.(route.$key) }), + label + }, ] }, [] as NavigationItem[],