X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Frouting%2Fredirect.service.ts;h=571822b767a3dd85b8ec749fb19853dc29f0a517;hb=23bdacf8ec24ce47a15529830e116911d7478598;hp=844f184b414ac6cb3baad62fcfa13c2b20d7450a;hpb=a51bad1accfade25916db0dadaeb879a182cf19b;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/routing/redirect.service.ts b/client/src/app/core/routing/redirect.service.ts index 844f184b4..571822b76 100644 --- a/client/src/app/core/routing/redirect.service.ts +++ b/client/src/app/core/routing/redirect.service.ts @@ -1,5 +1,5 @@ import { Injectable } from '@angular/core' -import { Router } from '@angular/router' +import { NavigationEnd, Router } from '@angular/router' import { ServerService } from '../server' @Injectable() @@ -8,6 +8,9 @@ export class RedirectService { static INIT_DEFAULT_ROUTE = '/videos/trending' static DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE + private previousUrl: string + private currentUrl: string + constructor ( private router: Router, private serverService: ServerService @@ -18,6 +21,7 @@ export class RedirectService { RedirectService.DEFAULT_ROUTE = config.instance.defaultClientRoute } + // Load default route this.serverService.configLoaded .subscribe(() => { const defaultRouteConfig = this.serverService.getConfig().instance.defaultClientRoute @@ -26,12 +30,34 @@ export class RedirectService { RedirectService.DEFAULT_ROUTE = defaultRouteConfig } }) + + // Track previous url + this.currentUrl = this.router.url + router.events.subscribe(event => { + if (event instanceof NavigationEnd) { + this.previousUrl = this.currentUrl + this.currentUrl = event.url + } + }) + } + + redirectToPreviousRoute () { + const exceptions = [ + '/verify-account' + ] + + if (this.previousUrl) { + const isException = exceptions.find(e => this.previousUrl.startsWith(e)) + if (!isException) return this.router.navigateByUrl(this.previousUrl) + } + + return this.redirectToHomepage() } - redirectToHomepage () { + redirectToHomepage (skipLocationChange = false) { console.log('Redirecting to %s...', RedirectService.DEFAULT_ROUTE) - this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { replaceUrl: true }) + this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange }) .catch(() => { console.error( 'Cannot navigate to %s, resetting default route to %s.', @@ -40,7 +66,7 @@ export class RedirectService { ) RedirectService.DEFAULT_ROUTE = RedirectService.INIT_DEFAULT_ROUTE - return this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { replaceUrl: true }) + return this.router.navigate([ RedirectService.DEFAULT_ROUTE ], { skipLocationChange }) }) }