-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
18 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
import { createRouter, createWebHistory, createWebHashHistory } from 'vue-router' | ||
import HomeView from '../views/HomeView.vue' | ||
import { createRouter, createWebHashHistory } from 'vue-router'; | ||
|
||
// Automatically import all views from the "views" directory | ||
const viewModules = import.meta.glob('../views/*.vue'); | ||
|
||
export const routes = Object.keys(viewModules).map((viewPath) => { | ||
const name = viewPath.split('/').pop().replace('.vue', ''); | ||
const path = name === 'HomeView' ? '/' : `/${name.replace('View', '').toLowerCase()}`; | ||
|
||
return { | ||
path: path, | ||
name: name.toLowerCase(), | ||
component: viewModules[viewPath], // Lazy-loaded components | ||
}; | ||
}); | ||
|
||
const router = createRouter({ | ||
history: createWebHashHistory(import.meta.env.BASE_URL), | ||
routes: [ | ||
{ | ||
path: '/', | ||
name: 'home', | ||
component: HomeView | ||
}, | ||
{ | ||
path: '/about', | ||
name: 'about', | ||
// route level code-splitting | ||
// this generates a separate chunk (About.[hash].js) for this route | ||
// which is lazy-loaded when the route is visited. | ||
component: () => import('../views/AboutView.vue') | ||
} | ||
] | ||
}) | ||
routes, | ||
}); | ||
|
||
export default router | ||
export default router; |