T
TanStack2mo ago
national-gold

Redirect to same route

When I try to redirect to the same route with a new search object it doesn't keep the search parameter from the redirect. I have tried with my mask and without it.
beforeLoad: async ({ search }) => {
console.log({ beforeLoad: search });
if (search.code && search.state) {
console.log('redirecting');
throw redirect({
to: '.',
search: { showPriority: true },
});
}
},
beforeLoad: async ({ search }) => {
console.log({ beforeLoad: search });
if (search.code && search.state) {
console.log('redirecting');
throw redirect({
to: '.',
search: { showPriority: true },
});
}
},
const search = Route.useSearch();
console.log({ priority: search });
const search = Route.useSearch();
console.log({ priority: search });
Outputs the logs beforeLoad: { code: ..., state: ... } 'redirecting' beforeLoad: { showPriority: true } priority: {}, priority: {},
5 Replies
crude-lavender
crude-lavender2mo ago
throw redirect({
to: '.',
search: (prev) => ({ ...prev, showPriority: true }),
});
throw redirect({
to: '.',
search: (prev) => ({ ...prev, showPriority: true }),
});
national-gold
national-goldOP2mo ago
Now that the code and state parameters always exist I am getting an endless loop. Because it is always redirecting with those params. I only want showPriority to go through to the component. Am I supposed to be returning something different from beforeLoad when it has the search params I want?
skilled-lime
skilled-lime2mo ago
just don't throw a redirect in that case then?
flat-fuchsia
flat-fuchsia2mo ago
What's the difference in terms of behavior when you throw a redirect or not?
skilled-lime
skilled-lime2mo ago
i meant: just throw the redirect if you want to redirect, here this means: if the search param is already present, then dont throw a redirect

Did you find this page helpful?