-
-
Notifications
You must be signed in to change notification settings - Fork 312
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
Include search params in toolpad navigation #4537
Comments
Makes sense to me! Would you be interested in contributing a PR? @apedroferreira Wdyt? |
I don't think we should assume all query parameters are valid for each path and should always transfer. IMO, clearing them as we do now should be the default behavior. We can think about designing an API that allows whitelisting certain parameters. I'm not sure yet how such API should look like. I can definitely imagine there are other scenarios where we want to let users intercept the navigation logic and have it alter behavior based on where they're navigating from/to or other conditions. Maybe we need more use cases? |
True, by default it would be wrong to always transfer URL params, but it is something we're even doing in Toolpad Studio for some specific parameters, so we could add a feature for it. Probably with a property in certain navigation items... By the way, the way we're doing this in Toolpad Studio is: const [searchParams] = useSearchParams();
const retainedSearch = React.useMemo(() => {
for (const name of searchParams.keys()) {
if (!RETAINED_URL_PARAMS.has(name)) {
searchParams.delete(name);
}
}
return searchParams.size > 0 ? `?${searchParams.toString()}` : '';
}, [searchParams]);
const navigation = React.useMemo(
() =>
pages.map(({ slug, displayName }) => ({
segment: `pages/${slug}${retainedSearch}`,
title: displayName,
})),
[pages, retainedSearch],
); |
I attempted to use a link that included search params in the global navigation for toolpad, but it was slicing of the search params.
Here is the diff that solved my problem:
Search keywords:
The text was updated successfully, but these errors were encountered: