vuejs / vue-router

🚦 The official router for Vue 2
http://v3.router.vuejs.org/
MIT License
18.99k stars 5.06k forks source link

[Feature Request] Add navigator outside component #3816

Closed joojaewoo closed 1 year ago

joojaewoo commented 1 year ago

What problem does this feature solve?

I recently converted to vue2.7 and vite. I imported the existing router object and used it outside the component, but I can't use it anymore because of the circular reference problem. It would be nice to create a function that can be routed outside the component. like react-router

What does the proposed API look like?

// axios
import { navigate } from 'vue-router'

axios.interceptors.response.use((res) => {
    navigate(path);
})
posva commented 1 year ago

You need to solve your circular reference. It's simply not possible to create such API because it depends on the router instance created with new VueRouter().