valaxy icon indicating copy to clipboard operation
valaxy copied to clipboard

feat: allow router instance in js/ts

Open hairyf opened this issue 3 years ago • 4 comments

Currently, to use the router, you must pass the component's useRouter

I think we can export router instance for those who need

import { router } from 'valaxy/client'
router.push('...')

hairyf avatar Jul 25 '22 09:07 hairyf

router is from vue-router.

They behave exactly the same, and I think it's always correct to import from vue-router.

import { router } from 'vue-router'

YunYouJun avatar Jul 25 '22 17:07 YunYouJun

I think yes, as long as we can get it, but it doesn't seem to be supported at the moment

image

hairyf avatar Jul 26 '22 02:07 hairyf

Use it like this.

import { useRouter } from 'vue-router'
const router = useRouter()

YunYouJun avatar Jul 27 '22 12:07 YunYouJun

No, we can't get the router outside the component via useRouter, it only works during setup

hairyf avatar Jul 28 '22 16:07 hairyf

useRouter need and should only works durint setup.

Even if we export from Valaxy, it needs to be initialized in Setup.

YunYouJun avatar Oct 02 '22 13:10 YunYouJun

If you want a instance, this.$router can be achieved in Vue.

https://router.vuejs.org/guide/#javascript

YunYouJun avatar Oct 02 '22 19:10 YunYouJun