Skip to content

Commit fb7945c

Browse files
committed
refactor: define routes in createRouter() for better autocompletion
After this commit, the `route` & `typescript-route` templates have more duplication than before. I'll investigate later to see if the code templates can be further simplified.
1 parent 9312482 commit fb7945c

File tree

2 files changed

+30
-36
lines changed

2 files changed

+30
-36
lines changed
Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
import { createRouter, createWebHistory } from 'vue-router'
22
import Home from '../views/Home.vue'
33

4-
const routes = [
5-
{
6-
path: '/',
7-
name: 'Home',
8-
component: Home
9-
},
10-
{
11-
path: '/about',
12-
name: 'About',
13-
// route level code-splitting
14-
// this generates a separate chunk (About.[hash].js) for this route
15-
// which is lazy-loaded when the route is visited.
16-
component: () => import('../views/About.vue')
17-
}
18-
]
19-
204
const router = createRouter({
215
history: createWebHistory(import.meta.env.BASE_URL),
22-
routes
6+
routes: [
7+
{
8+
path: '/',
9+
name: 'Home',
10+
component: Home
11+
},
12+
{
13+
path: '/about',
14+
name: 'About',
15+
// route level code-splitting
16+
// this generates a separate chunk (About.[hash].js) for this route
17+
// which is lazy-loaded when the route is visited.
18+
component: () => import('../views/About.vue')
19+
}
20+
]
2321
})
2422

2523
export default router
Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,23 @@
11
import { createRouter, createWebHistory } from 'vue-router'
2-
import type { RouteRecordRaw } from 'vue-router'
3-
42
import Home from '../views/Home.vue'
53

6-
const routes: Array<RouteRecordRaw> = [
7-
{
8-
path: '/',
9-
name: 'Home',
10-
component: Home
11-
},
12-
{
13-
path: '/about',
14-
name: 'About',
15-
// route level code-splitting
16-
// this generates a separate chunk (About.[hash].js) for this route
17-
// which is lazy-loaded when the route is visited.
18-
component: () => import('../views/About.vue')
19-
}
20-
]
21-
224
const router = createRouter({
235
history: createWebHistory(import.meta.env.BASE_URL),
24-
routes
6+
routes: [
7+
{
8+
path: '/',
9+
name: 'Home',
10+
component: Home
11+
},
12+
{
13+
path: '/about',
14+
name: 'About',
15+
// route level code-splitting
16+
// this generates a separate chunk (About.[hash].js) for this route
17+
// which is lazy-loaded when the route is visited.
18+
component: () => import('../views/About.vue')
19+
}
20+
]
2521
})
2622

2723
export default router

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy