The route will be altered once the route transition or animation has been initiated

As route change triggers an animation, I have a black div that slides from the bottom to the top of the page during transition.

The animation of the sliding div is working correctly. However, the issue arises when the route changes simultaneously with the start of the div's animation, disrupting the smooth transition between routes. I aim for the route to change only when the div completely covers the whole page to ensure a seamless transition.

Should I consider a different approach to address this issue?

https://i.sstatic.net/BTF8C.gif

app.component.html:

<router-outlet #myOutlet="outlet"></router-outlet>
<div class="transition-overlay" [@translate]="getDepth(myOutlet)"></div>

app.component.ts:

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.scss'],
  animations: [
    trigger('translate', [
      state('1', style({transform: 'translateY(100vh)'})),
      state('2', style({transform: 'translateY(-100vh)'})),
      transition('1=>2', [ animate('1500ms ease-in-out')]),
      transition('2=>1', [ animate('1500ms ease-in-out')])
    ])
  ]
})
export class AppComponent implements OnInit, AfterViewInit {

  ...

  getDepth(outlet) {
    return outlet.activatedRouteData['depth'];
  }

}

app-routing.module.ts:

const routes: Routes = [
  {path: '', component: HomeComponent, data: { depth: 1 }},
  {path: 'cases', component: WorkComponent, data: { depth: 2 }},
];

Answer №1

Implement the usage of Router Resolver to ensure that the animation completes before transitioning from one route to another.

Check out the Angular documentation for more information on Router Resolver.

Here is an example code snippet:

{
  path: '',
  component: HomeComponent,
  data: { depth: 1 },
  resolve: { items: SomeResolver }
}

Below is the implementation of the resolver:

import { Injectable } from '@angular/core';
import { APIService } from './api.service';

import { Resolve } from '@angular/router';

import { ActivatedRouteSnapshot } from '@angular/router';

@Injectable()
export class SomeResolver implements Resolve<any> {
  constructor(private apiService: APIService) {}

  resolve(route: ActivatedRouteSnapshot) {
    return **your condition**;
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Wireless web platform/program

I have been tasked with creating an app that will display real-time power data from a website. The challenge is that I do not have access to the backend of the site, which means I am unable to use PHP protocols to pull the data into my app. I attempted to ...

Accessing enum values in a view with Typescript and AngularJS version 1.5

Recently started working with Angular 1.5 and Typescript I have a service that returns data in an array format called devices.headerEntries: [{name:id,value:45} ,{name:Mode,value:1},{name:State,value:2},{name:serialnum,value:123434} I created a componen ...

Problem with RxJS array observable functionality not meeting expectations

I am struggling with an Angular service that contains an array of custom objects and an observable of this array. An external component subscribes to the observable but does not respond when the list is modified. Additionally, the mat-table, which uses the ...

Jquery scroll animation not reaching the intended position when scrolling upwards

While developing a new feature for my music player, I encountered an issue with centering the track/div upon clicking in the scrollable parent div. Sometimes it doesn't scroll to the center as intended and instead scrolls erratically to the top of the ...

Make a diagonally slanted border for a cell

Is it feasible to create a table with diagonal borders using CSS or jQuery, similar to the one shown below? I would welcome any ideas on how this can be achieved. ...

Using Angular to send a text to an injection service

i have developed a generic CRUD service that utilizes HttpClient through Dependency Injection (DI). However, I need to include another value in the constructor of this service. How can I achieve this? the issue arises when attempting to define this additi ...

Resolution of JSP/HTML Pages

Looking for guidance on adjusting the height and width of JSP/HTML pages to accommodate various monitor resolutions. How can I ensure that my page looks good and fits properly on all types of monitors? Any tips on setting height and width in a JSP would ...

Models reference each other incorrectly, causing a problem of circular dependencies

file-admin.ts import mongoose, { Schema, Document } from 'mongoose'; import UserRole, { IUserRole } from './user-role.model'; export interface IFileAdmin extends Document { role: IUserRole; } let fileAdminSchema = new Schema<IF ...

"Error: The update depth has exceeded the limit while trying to use the

I've been working on implementing localStorage in NextJs using TypeScript by following this guide at , but I am encountering an error. https://i.sstatic.net/NX78a.png Specifically, the error occurs on the context provider repeatedly. Below is the c ...

Experiencing an unusual gap following the menu on mobile view for my WordPress website?

I recently launched a WordPress website dedicated to education. In order to make some adjustments, I added subheaders to each page with a simple display:none setting. Surprisingly, while everything looked perfect on desktop view, I noticed some extra spa ...

Unable to choose radio button again

Check out this fun web quiz I created! I'm having some trouble with the back button functionality. Whenever a user clicks back, I want to restore their previous choice but for some reason it's not working as expected. Take a look at my go_back ...

Effortlessly adding loading spinners to images with Ionic 2, Ionic 3, and Ionic 4!

My Ionic2 application utilizes ion-img to properly load images, but I am seeking a way to notify the user that the picture is loading. Any suggestions would be greatly appreciated! EDIT : If you must use the ion-img tag, here is the solution. Otherwise, c ...

Detecting collisions on a tile map using only JavaScript

Currently, I am developing a tile-based game using a traditional method (utilizing two for loops) and struggling with writing collision detection. I want the blue square to remain on the screen and appear on top of the tiles once the start button is clicke ...

Javascript/Typescript Performance Evaluation

I am looking to create a visual report in the form of a table that displays the count of each rating based on the date. The ratings are based on a scale of 1 to 5. Below is the object containing the data: [ { "Date": "01/11/2022", ...

The alignment of the textarea is off due to an issue with the md

I'm experiencing an issue with the alignment of options in my form. The md-maxlength attribute is causing one line to be higher than the rest, as shown in the image below. https://i.sstatic.net/3J3Ts.png My goal is to move that specific textarea one ...

Navigation bar stays concealed on mobile devices until manually dragged down with a touch

I am in the process of creating a mobile website (non-native) for an iPhone 4. I want to include a "header" that is 80 pixels high and 100% wide, but remains hidden until the user swipes down on the screen. I found a helpful article that almost meets my n ...

Is it possible to dynamically add an id or class to an element using document.createElement in JavaScript?

As a beginner in the world of JavaScript, I understand that the code structure I have used here may not be ideal for real-world applications. However, I am using it to practice my understanding of for loops and fetching JSON data. My main query is whether ...

How to implement a dynamic tag using TypeScript in React?

How can I implement dynamic tag typing in React using TypeScript? Take a look at the following code snippet: interface CompProps { tag: string; } const MyComponent: React.FunctionComponent<CompProps> = ({ tag = "div", children }) => { co ...

What is the reason for the presence of "CTYPE" in my HTML upon refreshing the page?

As I am utilizing Harp and Bootstrap for my project, I am encountering a peculiar issue. Upon refreshing the page, I notice that the text ""CTYPE html>"" is inserted within the body tags. Can anyone shed light on why this is happening? ...

When utilizing the HTML select element, the <option> tag may only display the initial letter of the chosen option

Here is a snippet of my PHP code: <?php if($_POST['post'] == 'Post') { $cat = $_POST['cat']; $update = "UPDATE table SET category='$cat' WHERE id = '$id' "; $result = mys ...