mirror of
https://github.com/maciejpedzich/racemash.git
synced 2024-11-27 16:15:47 +01:00
Add scrollBehaviour function to scroll to fragment
This commit is contained in:
parent
964ae1e965
commit
6b30a229bd
@ -1,4 +1,11 @@
|
|||||||
import { createRouter, createWebHistory } from 'vue-router';
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
||||||
|
|
||||||
|
import {
|
||||||
|
NavigationGuardNext,
|
||||||
|
RouteLocationNormalized,
|
||||||
|
createRouter,
|
||||||
|
createWebHistory
|
||||||
|
} from 'vue-router';
|
||||||
|
|
||||||
import Home from '@/views/Home.vue';
|
import Home from '@/views/Home.vue';
|
||||||
import { useVote } from '@/composables/useVote';
|
import { useVote } from '@/composables/useVote';
|
||||||
@ -20,12 +27,15 @@ const routes = [
|
|||||||
path: '/ranking',
|
path: '/ranking',
|
||||||
name: 'Ranking',
|
name: 'Ranking',
|
||||||
component: () => import('../views/Ranking.vue'),
|
component: () => import('../views/Ranking.vue'),
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
beforeEnter: (
|
||||||
beforeEnter: (_to: unknown, _from: unknown, next: () => void) => {
|
_to: RouteLocationNormalized,
|
||||||
|
_from: RouteLocationNormalized,
|
||||||
|
next: NavigationGuardNext
|
||||||
|
) => {
|
||||||
if (userSubmittedAllVotes.value) {
|
if (userSubmittedAllVotes.value) {
|
||||||
return next();
|
return next();
|
||||||
} else {
|
} else {
|
||||||
return false;
|
return next('/');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -33,7 +43,14 @@ const routes = [
|
|||||||
|
|
||||||
const router = createRouter({
|
const router = createRouter({
|
||||||
history: createWebHistory(process.env.BASE_URL),
|
history: createWebHistory(process.env.BASE_URL),
|
||||||
routes
|
routes,
|
||||||
|
scrollBehavior(to, _from, _savedPosition) {
|
||||||
|
if (to.hash) {
|
||||||
|
return {
|
||||||
|
el: to.hash
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
export default router;
|
export default router;
|
||||||
|
Loading…
Reference in New Issue
Block a user