Skip to content

Commit

Permalink
refactor: simplify the implementaiton #55
Browse files Browse the repository at this point in the history
Signed-off-by: seven <[email protected]>
  • Loading branch information
Blankll committed May 6, 2024
1 parent 35997f8 commit 03348a1
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 88 deletions.
15 changes: 6 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
import { createApp } from 'vue';
import App from './App.vue';
import store from './store';
import { setupRouter } from './router';
import { router } from './router';
import { lang } from './lang';

import './assets/styles/normalize.css';
import './assets/styles/theme.scss';

async function bootstrap() {
const app = createApp(App);
const app = createApp(App);

setupRouter(app);
app.use(store);
app.use(lang);
app.use(router);
app.use(store);
app.use(lang);

app.mount('#app');
}
bootstrap();
app.mount('#app');
45 changes: 0 additions & 45 deletions src/router/basic.ts

This file was deleted.

26 changes: 0 additions & 26 deletions src/router/guards.ts

This file was deleted.

69 changes: 61 additions & 8 deletions src/router/index.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,67 @@
import { createMemoryHistory, createRouter } from 'vue-router';
import { basicRoutes } from './basic';
import { createRouterGuards } from './guards';

export const router = createRouter({
import { useUserStore } from '../store';

const LOGIN_PATH = '/login';

const router = createRouter({
history: createMemoryHistory(),
scrollBehavior: () => ({ left: 0, top: 0 }),
routes: basicRoutes,
routes: [
{
path: '/login',
name: 'Login',
meta: {
keepAlive: false,
},
component: () => import('../views/login/index.vue'),
},
{
path: '/',
name: 'Layout',
meta: {
keepAlive: false,
},
component: () => import('../layout/index.vue'),
redirect: '/connect',
children: [
{
name: 'Connect',
path: '/connect',
meta: {
keepAlive: false,
},
component: () => import('../views/connect/index.vue'),
},
{
name: 'History',
path: '/history',
meta: {
keepAlive: false,
},
component: () => import('../views/history/index.vue'),
},
{
name: 'Setting',
path: '/setting',
meta: {
keepAlive: false,
},
component: () => import('../views/setting/index.vue'),
},
],
},
],
});

router.beforeEach(async (to, from, next) => {
const userStore = useUserStore();
const token = userStore.getToken;
if (to.meta.requiresAuth && !token) {
next(LOGIN_PATH);
} else {
next();
}
});

export async function setupRouter(app: App) {
createRouterGuards(router);
app.use(router);
}
export { router };

0 comments on commit 03348a1

Please sign in to comment.