useRouteUtils.ts 310 B

123456789101112
  1. export const useRouteUtils = () => {
  2. const route = useRoute()
  3. const getIdFromRoute = (): number => {
  4. if (!route.params.id || !/\d+/.test(route.params.id as string)) {
  5. throw new Error('No id found in route')
  6. }
  7. return parseInt(route.params.id as string)
  8. }
  9. return { getIdFromRoute }
  10. }