Open History to see the last commit
1import { createRouter, createWebHistory } from 'vue-router'
2import { noop } from '@tanstack/vue-query'
3import { queryClient } from './queryClient'
4import { contactsQueries } from './services/contacts/queries'
5import RootView from './routes/RootView.vue'
6import IndexView from './routes/IndexView.vue'
7import ContactView from './routes/ContactView.vue'
8import EditView from './routes/EditView.vue'
9import NewView from './routes/NewView.vue'
10β
11export const router = createRouter({
12 history: createWebHistory(),
13 routes: [
14 {
15 path: '/',
16 component: RootView,
17 children: [
18 { path: '', component: IndexView },
19 { path: 'contacts/new', component: NewView },
20 { path: 'contacts/:contactId', component: ContactView, props: true },
21 { path: 'contacts/:contactId/edit', component: EditView, props: true },
22 ],
23 },
24 ],
25})
26β
27router.beforeResolve(async (to) => {
28 const q = typeof to.query.q === 'string' ? to.query.q : ''
29 const contactId =
30 typeof to.params.contactId === 'string' ? to.params.contactId : undefined
31β
32 await Promise.all([
33 queryClient
34 .query({ ...contactsQueries.list(q), staleTime: 'static' })
35 .catch(noop),
36 contactId &&
37 queryClient
38 .query({ ...contactsQueries.detail(contactId), staleTime: 'static' })
39 .catch(noop),
40 ])
41})