mirror of
https://github.com/aelve/guide.git
synced 2024-12-25 05:43:32 +03:00
50 lines
1.3 KiB
TypeScript
50 lines
1.3 KiB
TypeScript
import Router from 'vue-router'
|
|
|
|
function createRouter () {
|
|
return new Router({
|
|
mode: 'history',
|
|
fallback: false,
|
|
// TODO update vue-router when scroll issue will be fixed
|
|
// https://github.com/vuejs/vue-router/issues/2095
|
|
// Router doesnt support navigation to same anchor yet
|
|
// https://github.com/vuejs/vue-router/issues/1668
|
|
scrollBehavior (to, from, savedPosition) {
|
|
if (savedPosition) {
|
|
return savedPosition
|
|
} else if (to.hash) {
|
|
return { selector: to.hash, offset: { y: 96, x: 0 } }
|
|
} else {
|
|
return { x: 0, y: 0 }
|
|
}
|
|
},
|
|
routes: [
|
|
{
|
|
path: '/',
|
|
name: 'Index',
|
|
component: () => import('../page/Index.vue')
|
|
},
|
|
{
|
|
path: '/haskell/:category',
|
|
name: 'Category',
|
|
component: () => import('../page/CategoryPage.vue'),
|
|
props: (route) => ({ categoryId: route.params.category.split('#').shift().split('-').pop() })
|
|
},
|
|
{
|
|
path: '/haskell/search/results/',
|
|
name: 'SearchResults',
|
|
component: () => import('../page/SearchResults.vue'),
|
|
props: (route) => ({ query: route.query.query })
|
|
},
|
|
{
|
|
path: '*',
|
|
name: 'Page404',
|
|
component: () => import('../page/Page404.vue')
|
|
}
|
|
]
|
|
})
|
|
}
|
|
|
|
export {
|
|
createRouter
|
|
}
|