Created
April 14, 2020 12:03
-
-
Save manakuro/c36692e89c4d5a8ed8776529e95dfc48 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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