import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router' import {getToken} from "@/utils/token" import Login from '@/views/login/index.vue' import Home from '@/views/home/index.vue' import Error from '@/views/404/index.vue' import { onGetRouter } from '@/utils/userInfo' console.log(onGetRouter(),'getRouter'); const routes: Array<RouteRecordRaw> = [ { path:'/', redirect:'/login' }, { path: '/login', name: 'Login', component: Login }, { path: '/home', name: 'Home', component: Home, redirect:'/home/paybind', children:onGetRouter() }, { path: '/404', name: '404', component: Error } ] const router = createRouter({ history: createWebHistory(), routes }) router.beforeEach((to,from,next)=>{ const token:any = getToken if(token){ next() }else{ router.push('/login') } }) export default router