Skip to content

Unwanted Reload Full Page #2233

Closed Answered by posva
mdrakash asked this question in Help and Questions
Discussion options

You must be logged in to vote

By importing the router from the file where routes are declared you are not letting vue handle hmr properly:

  • change Login.vue -> router.ts needs to update because it imports it -> example.js imports from router so it also needs update -> Login.vue needs update because it imports it

The proper way is to use useRouter() in Login. If you still want to the external function pass router as an argument:

export default function test(router) {
  router.push('/');
}

And pass it in the component:

<template>
  <div>
    Login e
    <button @click.prevent="test($router)">Click Me</button>
  </div>
</template>

<script setup>
import test from '../example.js';
const router = useRouter() // we could a…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants