-
-
Notifications
You must be signed in to change notification settings - Fork 362
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 have this in my navigation: {
title: `${receiverData.receiver}`,
segment: receiverData.uncollectedDocket
? `${receiverData.uncollectedDocket.id}`
: `${uuidv4()}${receiverData.receiverID ? `?receiverID=${receiverData.receiverID}` : `?receiver=${receiverData.receiver}`}`,
} i'm purposefully adding the query parameters and if i
|
it's also stripping hash parameters. i guess i have to use path parameters for now? then they appear in the breadcrumbs? |
We don't want to use the segment to pass search parameters as it really just represents the path segment. But I wouldn't mind adding a const nav = [
{
segment: 'movies',
searchParams: new URLSearchParams({ foo: 'bar', baz: 'quux' })
children: [
{
segment: 'lord-of-the-rings',
searchParams: new URLSearchParams({ foo: 'hello' })
// /movies/lord-of-the-rings?foo=hello
},
{
segment: 'harry-potter',
// /movies/harry-potter'?foo=bar&baz=quux
},
{
segment: 'dune',
searchParams: new URLSearchParams()
// /movies/dune
},
],
},
]
Initially, for client side routers. But we just added a way to define a router-specific link component. With this it should be possible to create a custom router adapter that uses a plain anchor element with default behaviour.
It should be in the upcoming version according to this if you use the react router provider. |
i'll add it to my todo list. |
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: