问一个菜鸟问题

vue-router

#1

router.beforeEach((to, from, next) => {

alert(“a”);

next();

});
我想把守卫写在单独的文件里不想写在main.js里应该怎么写 怎么引入啊


#2

test.js

import router from './router'
router.beforeEach((to, from, next) => {

alert("a");

next();

});

main.js

import './test.js'