Better route transitions
This commit is contained in:
parent
5029d1da9c
commit
65406a222d
|
@ -8,7 +8,7 @@ import AppHeader from './components/AppHeader.vue'
|
||||||
<!-- keep relative for transition -->
|
<!-- keep relative for transition -->
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<RouterView v-slot="{ Component, route }">
|
<RouterView v-slot="{ Component, route }">
|
||||||
<Transition name="route">
|
<Transition :name="route.meta.transition">
|
||||||
<Component
|
<Component
|
||||||
:is="Component"
|
:is="Component"
|
||||||
:key="route.path" />
|
:key="route.path" />
|
||||||
|
|
|
@ -67,6 +67,30 @@
|
||||||
position: absolute;
|
position: absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* ROUTE TRANSITION - BACK */
|
||||||
|
|
||||||
|
.route_back-move,
|
||||||
|
.route_back-enter-active,
|
||||||
|
.route_back-leave-active {
|
||||||
|
transition: all .8s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.route_back-enter-from {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(-100vw);
|
||||||
|
}
|
||||||
|
|
||||||
|
.route_back-leave-to {
|
||||||
|
opacity: 0;
|
||||||
|
transform: translateX(100vw);
|
||||||
|
}
|
||||||
|
|
||||||
|
.route_back-leave-active {
|
||||||
|
position: absolute;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* SLIDE LEFT */
|
/* SLIDE LEFT */
|
||||||
|
|
||||||
.slide_left-move,
|
.slide_left-move,
|
||||||
|
|
|
@ -9,18 +9,36 @@ const router = createRouter({
|
||||||
path: '/',
|
path: '/',
|
||||||
name: 'home',
|
name: 'home',
|
||||||
component: HomeView,
|
component: HomeView,
|
||||||
|
meta: { transition: '' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/daily',
|
path: '/daily',
|
||||||
name: 'daily',
|
name: 'daily',
|
||||||
component: () => import('../views/GameView.vue'),
|
component: () => import('../views/GameView.vue'),
|
||||||
|
meta: { transition: 'route' },
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/random',
|
path: '/random',
|
||||||
name: 'random',
|
name: 'random',
|
||||||
component: () => import('../views/GameView.vue'),
|
component: () => import('../views/GameView.vue'),
|
||||||
|
meta: { transition: 'route' },
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
|
|
||||||
|
router.afterEach((to, from) => {
|
||||||
|
// No transition when direct access
|
||||||
|
if (!from.name) {
|
||||||
|
to.meta.transition = ''
|
||||||
|
}
|
||||||
|
// Back animation when going back to home
|
||||||
|
else if (to.path === '/') {
|
||||||
|
to.meta.transition = 'route_back'
|
||||||
|
}
|
||||||
|
// Normal forward animation
|
||||||
|
else {
|
||||||
|
to.meta.transition = 'route'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
export default router
|
export default router
|
||||||
|
|
Loading…
Reference in New Issue
Block a user