2022-08-03 21:26:42 +08:00
|
|
|
import Vue from "vue";
|
|
|
|
|
import VueRouter from "vue-router";
|
2022-08-02 10:16:07 +08:00
|
|
|
|
2022-08-03 21:26:42 +08:00
|
|
|
Vue.use(VueRouter);
|
2022-08-02 10:16:07 +08:00
|
|
|
|
|
|
|
|
const createRouter = () =>
|
|
|
|
|
new VueRouter({
|
2022-08-03 21:26:42 +08:00
|
|
|
scrollBehavior: () => ({ y: 0 }),
|
|
|
|
|
});
|
2022-08-02 10:16:07 +08:00
|
|
|
|
2022-08-03 21:26:42 +08:00
|
|
|
const router = createRouter();
|
|
|
|
|
|
|
|
|
|
router.beforeEach((to, from, next) => {
|
|
|
|
|
if (localStorage.getItem("token")) {
|
|
|
|
|
next();
|
|
|
|
|
} else if (to.fullPath === "/logo") {
|
|
|
|
|
next();
|
|
|
|
|
} else {
|
|
|
|
|
next("/logo");
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
export default router;
|