T
TanStack3y ago
rare-sapphire

Handling 404 on fetch

If I had a query, something like the below in my view user page
const { data: user } = userQueries.getUser('1234'); // just a basic query to get the user based on the prop
const { data: user } = userQueries.getUser('1234'); // just a basic query to get the user based on the prop
Where this will actual throw a 404 error, what would be the best way for me to redirect from the current page (UserView) back to the main table page (UserIndex)? Probay important to note that userQueries comes from a composable outside of the component
3 Replies
rare-sapphire
rare-sapphireOP3y ago
I know I have onError in the query but I shouldn't be doing routing from there...
correct-apricot
correct-apricot3y ago
Maybe global onError handler would work for you?
const vueQueryPluginOptions: VueQueryPluginOptions = {
queryClientConfig: {
defaultOptions: { queries: { onError: () => {...}} },
},
};
app.use(VueQueryPlugin, vueQueryPluginOptions);
const vueQueryPluginOptions: VueQueryPluginOptions = {
queryClientConfig: {
defaultOptions: { queries: { onError: () => {...}} },
},
};
app.use(VueQueryPlugin, vueQueryPluginOptions);
rare-sapphire
rare-sapphireOP3y ago
Each 404 would need to be handled differently depending on where it is I mean is it a bad thing to use routing in a composable?

Did you find this page helpful?