Refactor to signel use route resolving method

This commit is contained in:
Fayaz Ahmed
2024-08-28 01:10:05 +05:30
parent deeb580fee
commit 4b5880eb30
10 changed files with 84 additions and 97 deletions
@@ -0,0 +1,21 @@
import { useRouter, useRoute } from 'dashboard/composables/route';
/**
* Composable for replacing the current route with a new one if it's different.
* @param {string} name - The name of the route to replace with.
* @param {Object} params - The params to pass to the new route.
* @returns {Function} A function that replaces the route when called.
*/
export const useReplaceRoute = () => {
const router = useRouter();
const route = useRoute();
return (name, params = {}) => {
if (route.name !== name) {
return router.replace({ name, params });
}
return undefined;
};
};
export default useReplaceRoute;