Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created April 14, 2020 12:03
Show Gist options
  • Save manakuro/c36692e89c4d5a8ed8776529e95dfc48 to your computer and use it in GitHub Desktop.
Save manakuro/c36692e89c4d5a8ed8776529e95dfc48 to your computer and use it in GitHub Desktop.
import { reactive, toRefs, watch } from '@vue/composition-api'
import { Route } from 'vue-router'
import { getRuntimeVM } from '~/utils/runtime'
type State = {
route: Route
}
const useRouter = () => {
const vm = getRuntimeVM()
const state = reactive<State>({
route: vm.$route
})
watch(
() => vm.$route,
(r) => {
state.route = r as any
}
)
return { ...toRefs(state), router: vm.$router }
}
export default useRouter
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment