I need a component(brand name) to animate based on the previous route in angular. That is when the previous route is home then the component should be loaded from right, and if the previous route is brand model then the component should be loaded from left. I want to add code to animate, in the component itself.
I could get the previous route in the component using the service
import { Injectable } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
@Injectable({
providedIn: 'root'
})
export class RouteService {
private previousUrl: string;
private currentUrl: string;
constructor(private router: Router) {
this.currentUrl = this.router.url;
router.events.subscribe(event => {
if (event instanceof NavigationEnd) {
this.previousUrl = this.currentUrl;
this.currentUrl = event.url;
}
});
}
public getPreviousUrl() {
return this.previousUrl;
}
}
But not able to animate after loading the page. Is there any way to achieve this?