Reputation: 11
is there any differences between using composition hook to inject dependencies useRouter()
and ES6 module import import router from './router'
router.ts
export default createRouter({
history: createWebHashHistory(process.env.BASE_URL),
// history: createWebHistory(process.env.BASE_URL),
routes,
});
page.ts using composition hook
export default {
setup() {
const router = useRouter()
router.back()
}
};
page.ts using ES6 import
import router from './router.ts'
export default {
setup() {
router.back()
}
};
Upvotes: 0
Views: 214
Reputation: 1843
No, there is no difference between Vue Router's useRouter()
method and importing the router directly. You can see this in the source code for useRouter
, which is just three lines that return the router instance.
Upvotes: 1