|
|
@@ -13,6 +13,7 @@ import {
|
|
|
} from './name';
|
|
|
import Home from '@pages/home/index.vue';
|
|
|
import Login from '@pages/login/index.vue';
|
|
|
+import {storeToRefs, useUserStore} from '@stores';
|
|
|
|
|
|
const routes: RouteRecordRaw[] = [
|
|
|
{
|
|
|
@@ -47,4 +48,18 @@ export const router = createRouter({
|
|
|
routes,
|
|
|
});
|
|
|
|
|
|
+router.beforeEach(function(to) {
|
|
|
+ const {name} = to;
|
|
|
+ if (name) {
|
|
|
+ const userStore = useUserStore();
|
|
|
+ const {user} = storeToRefs(userStore);
|
|
|
+
|
|
|
+ if (!user.value.token) {
|
|
|
+ // 判断是否登录
|
|
|
+ const matchList = [LOGIN_NAME, REGISTER_NAME];
|
|
|
+ if (!matchList.includes(name as symbol)) return LOGIN_PATH;
|
|
|
+ }
|
|
|
+ }
|
|
|
+});
|
|
|
+
|
|
|
export * from './name';
|