Skip to content

Instantly share code, notes, and snippets.

@perjansson
Last active May 25, 2018 11:14
Show Gist options
  • Save perjansson/0226e31d79dc796b5092cd1218eef523 to your computer and use it in GitHub Desktop.
Save perjansson/0226e31d79dc796b5092cd1218eef523 to your computer and use it in GitHub Desktop.
import { routerTransition } from 'router.animations'
...
@Component({
selector: '...',
styleUrls: ['...'],
templateUrl: './app.template.html',
animations: [routerTransition],
})
export class AppComponent {
private previousPath: string = ''
getPageTransition(routerOutlet: RouterOutlet) {
if (routerOutlet.isActivated) {
let transitionName = 'section'
const { path } = routerOutlet.activatedRoute.routeConfig
const isSame = this.previousPath === path
const isBackward = this.previousPath.startsWith(path)
const isForward = path.startsWith(this.previousPath)
if (isSame) {
transitionName = 'none'
} else if (isBackward && isForward) {
transitionName = 'initial'
} else if (isBackward) {
transitionName = 'backward'
} else if (isForward) {
transitionName = 'forward'
}
this.previousPath = path
return transitionName
}
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment