import type { Ref } from 'vue'

import { onLoad } from '@dcloudio/uni-app'

export default function useRouteParam<T>(key?: string): {
  routeParam: Ref<Record<string, any> | T>
} {
  const routeParam = ref<Record<string, any> | T>({})
  onLoad((option) => {
    routeParam.value = option
    if (key) {
      routeParam.value = option[key]
    }
  })

  return {
    routeParam,
  }
}
