import { useRandomName } from "./../utils/utils" ; import provideStore from "@/utils/provideStore" ; import { createRouter , createWebHistory , Router , RouteRecordRaw } from "vue-router" ; import store from "../store" ; const routes = [ { path : "/" , name : "LAYOUT" , redirect : "/home" , component : ( ) => import ( "../views/layout/index.vue" ) , children : [ { path : "home" , name : "HOME" , component : ( ) => import ( "../views/Home.vue" ) } , { path : "about" , name : "ABOUT" , component : ( ) => import ( "../views/About.vue" ) } ] } , { path : "/shop" , name : "SHOP" , component : ( ) => import ( "../views/shop/index.vue" ) } , { path : "/vuex" , name : "VUEX" , component : ( ) => import ( "../views/vuex/index.vue" ) } , { path : "/message" , name : "MESSAGE" , component : ( ) => import ( "../views/message/index.vue" ) } , { path : "/form" , name : "FORM" , component : ( ) => import ( "../views/message/form.vue" ) } , { path : "/video" , name : "Video" , component : ( ) => import ( "../views/video/index" ) } ] ; const router = createRouter ( { history : createWebHistory ( process . env . BASE_URL ) , routes } ) ; function RouterStack ( router ) { router . afterEach ( ( to , from ) => { if ( ! store . state . user . loginUser ) { store . commit ( "setUserInfo" , useRandomName ( ) ) ; } console . log ( "store" , store . state . user . loginUser ) ; console . log ( to , from ) ; console . log ( provideStore . planList . value ) ; } ) ; return router ; } RouterStack ( router ) ; export default router ;