I have a common js "fetch.js" to request data from server. when get a special code like -1, I want to redirect to /login. But I don't know how to access $router in fetch.js file.
Thanks.
Hello, your issue has been closed because it does not conform to our issue requirements. Please use the Issue Helper to create an issue - thank you!
Here is the solution, first add import:
import router from '@/path/to/router.js';
and then just use router.
(router.js is file with code export default new Router({ ...)
@dima74 Thank you very much.
Most helpful comment
Here is the solution, first add import:
and then just use router.
(
router.jsis file with codeexport default new Router({ ...)