Skip to content

Commit

Permalink
route module merge
Browse files Browse the repository at this point in the history
  • Loading branch information
AxyLm committed Sep 10, 2022
1 parent 79befc3 commit 586347f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 36 deletions.
3 changes: 0 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import { createApp } from 'vue';
import App from './app.vue';
import { router } from './route';
import 'tailwindcss/tailwind.css';
import './style/index.less';

const app = createApp(App);

Object.values(import.meta.globEager('./modules/*.ts')).forEach((i) => i.install?.(app));

app.use(router);

app.mount('#app');
55 changes: 55 additions & 0 deletions src/modules/router.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import {
createRouter,
createWebHistory,
NavigationGuardWithThis,
RouteRecordRaw,
} from 'vue-router';
import '@varlet/ui/es/snackbar/style';
import { type App } from 'vue';
import Layout from '~/layout/index.vue';

declare module 'vue-router' {
interface RouteMeta {
appBar?: boolean;
tabBar?: boolean;
batTitle?: string;
authorization?: boolean;
}
}

const routes: RouteRecordRaw[] = [
{
name: 'Layout',
path: '/',
component: Layout,
redirect: 'about',
children: [
{
name: 'Home',
path: 'home',
component: () => import('~/views/home/index.vue'),
},
{
name: 'About',
path: 'about',
component: () => import('~/views/about/index.vue'),
},
],
},
];

const beforeEach: NavigationGuardWithThis<undefined> = (to, from, next) => {
next();
};

export { routes };

export const install = (app: App<Element>) => {
const router = createRouter({
routes,
history: createWebHistory(),
});
router.beforeEach(beforeEach);

app.use(router);
};
32 changes: 0 additions & 32 deletions src/route/index.ts

This file was deleted.

2 changes: 1 addition & 1 deletion vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export default defineConfig({
}),
Icons({
scale: 1,
defaultStyle: 'display:inline-block', // Style apply to icons
defaultStyle: 'display:inline', // Style apply to icons
defaultClass: 'icon', // Class names apply to icons
autoInstall: true,
compiler: 'vue3',
Expand Down

0 comments on commit 586347f

Please sign in to comment.