|
@@ -1,21 +1,22 @@
|
|
|
+import { useSystemStore } from "@/stores/modules/systemStore";
|
|
|
+import { useWalletStore } from "@/stores/modules/walletStore";
|
|
|
|
|
|
-// import { useSystemStore } from '@/stores/modules/systemStore'
|
|
|
-// const systemStore = useSystemStore()
|
|
|
+export function createRouterGuards(router) {
|
|
|
+ const systemStore = useSystemStore();
|
|
|
+ const walletStore = useWalletStore();
|
|
|
+ // 路由拦截
|
|
|
+ router.beforeEach(async (to, from, next) => {
|
|
|
+ // 没有钱包,则跳转到login 页
|
|
|
+ if (!walletStore.account || !systemStore.token) {
|
|
|
+ next("/login");
|
|
|
+ }
|
|
|
+ next();
|
|
|
+ });
|
|
|
|
|
|
+ router.afterEach((to, _, next) => {});
|
|
|
|
|
|
-export function createRouterGuards(router, systemStore) {
|
|
|
-
|
|
|
- router.beforeEach(async (to, from, next) => {
|
|
|
-
|
|
|
- next()
|
|
|
- })
|
|
|
-
|
|
|
- router.afterEach((to, _, next) => {
|
|
|
-
|
|
|
- })
|
|
|
-
|
|
|
- // 错误
|
|
|
- router.onError(error => {
|
|
|
- console.log(error, '路由错误')
|
|
|
- })
|
|
|
-}
|
|
|
+ // 错误
|
|
|
+ router.onError((error) => {
|
|
|
+ console.log(error, "路由错误");
|
|
|
+ });
|
|
|
+}
|