I followed this tutorial to add route transition animations and it seems to work, but I am having more than 3 routes in my App. Now when I go to a page with animation: 'isRight'
when I am currently on isLeft
it works as expected, but when I am already on isRight
and want to go to another page which is on the right of the current one, it does not show any transition at all.
How can I make a transition dependent on where I am currently? How do I know if I have to make a transition to left or to right?
That is an example for my routes:
const routes: Routes = [
{ path: 'page1', component: Page1Component, data: {animation: isLeft} },
{ path: 'page2', component: Page2Component, data: { animation: 'isRight' } },
{ path: 'page3', component: Page3Component, data: { animation: 'isRight' } },
{ path: 'page4', component: Page4Component, data: { animation: 'isRight' } },
{ path: 'page5', component: Page5Component, data: { animation: 'isRight' } },
{ path: 'page6', component: Page6Component, data: { animation: 'isRight' } },
];
That is my animation:
export const slider =
trigger('routeAnimations', [
transition('* => isLeft', slideTo('left')),
transition('* => isRight', slideTo('right')),
transition('isRight => *', slideTo('left')),
transition('isLeft => *', slideTo('right'))
]);
function slideTo(direction) {
const optional = { optional: true };
return [
query(':enter, :leave', [
style({
position: 'absolute',
top: 0,
[direction]: 0,
width: '100%'
})
], optional),
query(':enter', [
style({ [direction]: '-100%'})
]),
group([
query(':leave', [
animate('600ms ease', style({ [direction]: '100%'}))
], optional),
query(':enter', [
animate('600ms ease', style({ [direction]: '0%'}))
])
]),
// Normalize the page style... Might not be necessary
// Required only if you have child animations on the page
query(':leave', animateChild()),
query(':enter', animateChild()),
];
}